mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1595745 - Part 3: Change String to use ClassSpec. r=mgaudet
Move String to ClassSpec using similar changes like done for Number in part 2. Differential Revision: https://phabricator.services.mozilla.com/D52659 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
c0763fac0e
commit
862270eda3
@ -58,7 +58,7 @@
|
||||
REAL(Date, InitViaClassSpec, OCLASP(Date)) \
|
||||
REAL(Math, InitMathClass, CLASP(Math)) \
|
||||
REAL(Number, InitViaClassSpec, OCLASP(Number)) \
|
||||
REAL(String, InitStringClass, OCLASP(String)) \
|
||||
REAL(String, InitViaClassSpec, OCLASP(String)) \
|
||||
REAL(RegExp, InitViaClassSpec, OCLASP(RegExp)) \
|
||||
REAL(Error, InitViaClassSpec, ERROR_CLASP(JSEXN_ERR)) \
|
||||
REAL(InternalError, InitViaClassSpec, ERROR_CLASP(JSEXN_INTERNALERR)) \
|
||||
|
@ -453,7 +453,7 @@ const JSClass StringObject::class_ = {
|
||||
js_String_str,
|
||||
JSCLASS_HAS_RESERVED_SLOTS(StringObject::RESERVED_SLOTS) |
|
||||
JSCLASS_HAS_CACHED_PROTO(JSProto_String),
|
||||
&StringObjectClassOps};
|
||||
&StringObjectClassOps, &StringObject::classSpec_};
|
||||
|
||||
/*
|
||||
* Perform the initial |RequireObjectCoercible(thisv)| and |ToString(thisv)|
|
||||
@ -3942,68 +3942,61 @@ Shape* StringObject::assignInitialShape(JSContext* cx,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY);
|
||||
}
|
||||
|
||||
JSObject* js::InitStringClass(JSContext* cx, Handle<GlobalObject*> global) {
|
||||
JSObject* StringObject::createPrototype(JSContext* cx, JSProtoKey key) {
|
||||
Rooted<JSString*> empty(cx, cx->runtime()->emptyString);
|
||||
Rooted<StringObject*> proto(
|
||||
cx, GlobalObject::createBlankPrototype<StringObject>(cx, global));
|
||||
cx, GlobalObject::createBlankPrototype<StringObject>(cx, cx->global()));
|
||||
if (!proto) {
|
||||
return nullptr;
|
||||
}
|
||||
if (!StringObject::init(cx, proto, empty)) {
|
||||
return nullptr;
|
||||
}
|
||||
return proto;
|
||||
}
|
||||
|
||||
/* Now create the String function. */
|
||||
RootedFunction ctor(cx);
|
||||
ctor = GlobalObject::createConstructor(
|
||||
cx, StringConstructor, cx->names().String, 1, gc::AllocKind::FUNCTION,
|
||||
&jit::JitInfo_String);
|
||||
if (!ctor) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!LinkConstructorAndPrototype(cx, ctor, proto)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!DefinePropertiesAndFunctions(cx, proto, nullptr, string_methods) ||
|
||||
!DefinePropertiesAndFunctions(cx, ctor, nullptr, string_static_methods)) {
|
||||
return nullptr;
|
||||
}
|
||||
static bool StringClassFinish(JSContext* cx, HandleObject ctor,
|
||||
HandleObject proto) {
|
||||
HandleNativeObject nativeProto = proto.as<NativeObject>();
|
||||
|
||||
// Create "trimLeft" as an alias for "trimStart".
|
||||
RootedValue trimFn(cx);
|
||||
RootedId trimId(cx, NameToId(cx->names().trimStart));
|
||||
RootedId trimAliasId(cx, NameToId(cx->names().trimLeft));
|
||||
if (!NativeGetProperty(cx, proto, trimId, &trimFn) ||
|
||||
!NativeDefineDataProperty(cx, proto, trimAliasId, trimFn, 0)) {
|
||||
return nullptr;
|
||||
if (!NativeGetProperty(cx, nativeProto, trimId, &trimFn) ||
|
||||
!NativeDefineDataProperty(cx, nativeProto, trimAliasId, trimFn, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create "trimRight" as an alias for "trimEnd".
|
||||
trimId = NameToId(cx->names().trimEnd);
|
||||
trimAliasId = NameToId(cx->names().trimRight);
|
||||
if (!NativeGetProperty(cx, proto, trimId, &trimFn) ||
|
||||
!NativeDefineDataProperty(cx, proto, trimAliasId, trimFn, 0)) {
|
||||
return nullptr;
|
||||
if (!NativeGetProperty(cx, nativeProto, trimId, &trimFn) ||
|
||||
!NativeDefineDataProperty(cx, nativeProto, trimAliasId, trimFn, 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Define escape/unescape, the URI encode/decode functions, and maybe
|
||||
* uneval on the global object.
|
||||
*/
|
||||
if (!JS_DefineFunctions(cx, global, string_functions)) {
|
||||
return nullptr;
|
||||
if (!JS_DefineFunctions(cx, cx->global(), string_functions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_String, ctor,
|
||||
proto)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return proto;
|
||||
return true;
|
||||
}
|
||||
|
||||
const ClassSpec StringObject::classSpec_ = {
|
||||
GenericCreateConstructor<StringConstructor, 1, gc::AllocKind::FUNCTION,
|
||||
&jit::JitInfo_String>,
|
||||
StringObject::createPrototype,
|
||||
string_static_methods,
|
||||
nullptr,
|
||||
string_methods,
|
||||
nullptr,
|
||||
StringClassFinish};
|
||||
|
||||
#define ____ false
|
||||
|
||||
/*
|
||||
|
@ -12,14 +12,12 @@
|
||||
|
||||
namespace js {
|
||||
|
||||
class GlobalObject;
|
||||
|
||||
JSObject* InitStringClass(JSContext* cx, Handle<GlobalObject*> global);
|
||||
|
||||
class StringObject : public NativeObject {
|
||||
static const unsigned PRIMITIVE_VALUE_SLOT = 0;
|
||||
static const unsigned LENGTH_SLOT = 1;
|
||||
|
||||
static const ClassSpec classSpec_;
|
||||
|
||||
public:
|
||||
static const unsigned RESERVED_SLOTS = 2;
|
||||
|
||||
@ -57,15 +55,13 @@ class StringObject : public NativeObject {
|
||||
static inline bool init(JSContext* cx, Handle<StringObject*> obj,
|
||||
HandleString str);
|
||||
|
||||
static JSObject* createPrototype(JSContext* cx, JSProtoKey key);
|
||||
|
||||
void setStringThis(JSString* str) {
|
||||
MOZ_ASSERT(getReservedSlot(PRIMITIVE_VALUE_SLOT).isUndefined());
|
||||
setFixedSlot(PRIMITIVE_VALUE_SLOT, StringValue(str));
|
||||
setFixedSlot(LENGTH_SLOT, Int32Value(int32_t(str->length())));
|
||||
}
|
||||
|
||||
/* For access to init, as String.prototype is special. */
|
||||
friend JSObject* js::InitStringClass(JSContext* cx,
|
||||
Handle<GlobalObject*> global);
|
||||
};
|
||||
|
||||
} // namespace js
|
||||
|
Loading…
Reference in New Issue
Block a user