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(Date, InitViaClassSpec, OCLASP(Date)) \
|
||||||
REAL(Math, InitMathClass, CLASP(Math)) \
|
REAL(Math, InitMathClass, CLASP(Math)) \
|
||||||
REAL(Number, InitViaClassSpec, OCLASP(Number)) \
|
REAL(Number, InitViaClassSpec, OCLASP(Number)) \
|
||||||
REAL(String, InitStringClass, OCLASP(String)) \
|
REAL(String, InitViaClassSpec, OCLASP(String)) \
|
||||||
REAL(RegExp, InitViaClassSpec, OCLASP(RegExp)) \
|
REAL(RegExp, InitViaClassSpec, OCLASP(RegExp)) \
|
||||||
REAL(Error, InitViaClassSpec, ERROR_CLASP(JSEXN_ERR)) \
|
REAL(Error, InitViaClassSpec, ERROR_CLASP(JSEXN_ERR)) \
|
||||||
REAL(InternalError, InitViaClassSpec, ERROR_CLASP(JSEXN_INTERNALERR)) \
|
REAL(InternalError, InitViaClassSpec, ERROR_CLASP(JSEXN_INTERNALERR)) \
|
||||||
|
@ -453,7 +453,7 @@ const JSClass StringObject::class_ = {
|
|||||||
js_String_str,
|
js_String_str,
|
||||||
JSCLASS_HAS_RESERVED_SLOTS(StringObject::RESERVED_SLOTS) |
|
JSCLASS_HAS_RESERVED_SLOTS(StringObject::RESERVED_SLOTS) |
|
||||||
JSCLASS_HAS_CACHED_PROTO(JSProto_String),
|
JSCLASS_HAS_CACHED_PROTO(JSProto_String),
|
||||||
&StringObjectClassOps};
|
&StringObjectClassOps, &StringObject::classSpec_};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform the initial |RequireObjectCoercible(thisv)| and |ToString(thisv)|
|
* Perform the initial |RequireObjectCoercible(thisv)| and |ToString(thisv)|
|
||||||
@ -3942,68 +3942,61 @@ Shape* StringObject::assignInitialShape(JSContext* cx,
|
|||||||
JSPROP_PERMANENT | JSPROP_READONLY);
|
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<JSString*> empty(cx, cx->runtime()->emptyString);
|
||||||
Rooted<StringObject*> proto(
|
Rooted<StringObject*> proto(
|
||||||
cx, GlobalObject::createBlankPrototype<StringObject>(cx, global));
|
cx, GlobalObject::createBlankPrototype<StringObject>(cx, cx->global()));
|
||||||
if (!proto) {
|
if (!proto) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!StringObject::init(cx, proto, empty)) {
|
if (!StringObject::init(cx, proto, empty)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
return proto;
|
||||||
|
}
|
||||||
|
|
||||||
/* Now create the String function. */
|
static bool StringClassFinish(JSContext* cx, HandleObject ctor,
|
||||||
RootedFunction ctor(cx);
|
HandleObject proto) {
|
||||||
ctor = GlobalObject::createConstructor(
|
HandleNativeObject nativeProto = proto.as<NativeObject>();
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create "trimLeft" as an alias for "trimStart".
|
// Create "trimLeft" as an alias for "trimStart".
|
||||||
RootedValue trimFn(cx);
|
RootedValue trimFn(cx);
|
||||||
RootedId trimId(cx, NameToId(cx->names().trimStart));
|
RootedId trimId(cx, NameToId(cx->names().trimStart));
|
||||||
RootedId trimAliasId(cx, NameToId(cx->names().trimLeft));
|
RootedId trimAliasId(cx, NameToId(cx->names().trimLeft));
|
||||||
if (!NativeGetProperty(cx, proto, trimId, &trimFn) ||
|
if (!NativeGetProperty(cx, nativeProto, trimId, &trimFn) ||
|
||||||
!NativeDefineDataProperty(cx, proto, trimAliasId, trimFn, 0)) {
|
!NativeDefineDataProperty(cx, nativeProto, trimAliasId, trimFn, 0)) {
|
||||||
return nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create "trimRight" as an alias for "trimEnd".
|
// Create "trimRight" as an alias for "trimEnd".
|
||||||
trimId = NameToId(cx->names().trimEnd);
|
trimId = NameToId(cx->names().trimEnd);
|
||||||
trimAliasId = NameToId(cx->names().trimRight);
|
trimAliasId = NameToId(cx->names().trimRight);
|
||||||
if (!NativeGetProperty(cx, proto, trimId, &trimFn) ||
|
if (!NativeGetProperty(cx, nativeProto, trimId, &trimFn) ||
|
||||||
!NativeDefineDataProperty(cx, proto, trimAliasId, trimFn, 0)) {
|
!NativeDefineDataProperty(cx, nativeProto, trimAliasId, trimFn, 0)) {
|
||||||
return nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define escape/unescape, the URI encode/decode functions, and maybe
|
* Define escape/unescape, the URI encode/decode functions, and maybe
|
||||||
* uneval on the global object.
|
* uneval on the global object.
|
||||||
*/
|
*/
|
||||||
if (!JS_DefineFunctions(cx, global, string_functions)) {
|
if (!JS_DefineFunctions(cx, cx->global(), string_functions)) {
|
||||||
return nullptr;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_String, ctor,
|
return true;
|
||||||
proto)) {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return proto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
#define ____ false
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -12,14 +12,12 @@
|
|||||||
|
|
||||||
namespace js {
|
namespace js {
|
||||||
|
|
||||||
class GlobalObject;
|
|
||||||
|
|
||||||
JSObject* InitStringClass(JSContext* cx, Handle<GlobalObject*> global);
|
|
||||||
|
|
||||||
class StringObject : public NativeObject {
|
class StringObject : public NativeObject {
|
||||||
static const unsigned PRIMITIVE_VALUE_SLOT = 0;
|
static const unsigned PRIMITIVE_VALUE_SLOT = 0;
|
||||||
static const unsigned LENGTH_SLOT = 1;
|
static const unsigned LENGTH_SLOT = 1;
|
||||||
|
|
||||||
|
static const ClassSpec classSpec_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const unsigned RESERVED_SLOTS = 2;
|
static const unsigned RESERVED_SLOTS = 2;
|
||||||
|
|
||||||
@ -57,15 +55,13 @@ class StringObject : public NativeObject {
|
|||||||
static inline bool init(JSContext* cx, Handle<StringObject*> obj,
|
static inline bool init(JSContext* cx, Handle<StringObject*> obj,
|
||||||
HandleString str);
|
HandleString str);
|
||||||
|
|
||||||
|
static JSObject* createPrototype(JSContext* cx, JSProtoKey key);
|
||||||
|
|
||||||
void setStringThis(JSString* str) {
|
void setStringThis(JSString* str) {
|
||||||
MOZ_ASSERT(getReservedSlot(PRIMITIVE_VALUE_SLOT).isUndefined());
|
MOZ_ASSERT(getReservedSlot(PRIMITIVE_VALUE_SLOT).isUndefined());
|
||||||
setFixedSlot(PRIMITIVE_VALUE_SLOT, StringValue(str));
|
setFixedSlot(PRIMITIVE_VALUE_SLOT, StringValue(str));
|
||||||
setFixedSlot(LENGTH_SLOT, Int32Value(int32_t(str->length())));
|
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
|
} // namespace js
|
||||||
|
Loading…
Reference in New Issue
Block a user