зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1103368, part 3 - Ban stub getter/setter arguments to JSObject::define{Generic,Property,Element} and js::SetPropertyIgnoringNamedGetter. r=bhackett.
--HG-- extra : rebase_source : c22527613154df11344f2e66060d7e6dae61b6de
This commit is contained in:
Родитель
317e18f2b5
Коммит
37a9b9a235
|
@ -457,8 +457,8 @@ intl_availableLocales(JSContext *cx, CountAvailable countAvailable,
|
|||
RootedAtom a(cx, Atomize(cx, lang, strlen(lang)));
|
||||
if (!a)
|
||||
return false;
|
||||
if (!JSObject::defineProperty(cx, locales, a->asPropertyName(), t,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE))
|
||||
if (!JSObject::defineProperty(cx, locales, a->asPropertyName(), t, nullptr, nullptr,
|
||||
JSPROP_ENUMERATE))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -720,11 +720,8 @@ InitCollatorClass(JSContext *cx, HandleObject Intl, Handle<GlobalObject*> global
|
|||
|
||||
// 8.1
|
||||
RootedValue ctorValue(cx, ObjectValue(*ctor));
|
||||
if (!JSObject::defineProperty(cx, Intl, cx->names().Collator, ctorValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
{
|
||||
if (!JSObject::defineProperty(cx, Intl, cx->names().Collator, ctorValue, nullptr, nullptr, 0))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ctor;
|
||||
}
|
||||
|
@ -1211,8 +1208,8 @@ InitNumberFormatClass(JSContext *cx, HandleObject Intl, Handle<GlobalObject*> gl
|
|||
|
||||
// 8.1
|
||||
RootedValue ctorValue(cx, ObjectValue(*ctor));
|
||||
if (!JSObject::defineProperty(cx, Intl, cx->names().NumberFormat, ctorValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
if (!JSObject::defineProperty(cx, Intl, cx->names().NumberFormat, ctorValue, nullptr, nullptr,
|
||||
0))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1668,7 +1665,7 @@ InitDateTimeFormatClass(JSContext *cx, HandleObject Intl, Handle<GlobalObject*>
|
|||
// 8.1
|
||||
RootedValue ctorValue(cx, ObjectValue(*ctor));
|
||||
if (!JSObject::defineProperty(cx, Intl, cx->names().DateTimeFormat, ctorValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
nullptr, nullptr, 0))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2043,11 +2040,8 @@ js_InitIntlClass(JSContext *cx, HandleObject obj)
|
|||
return nullptr;
|
||||
|
||||
RootedValue IntlValue(cx, ObjectValue(*Intl));
|
||||
if (!JSObject::defineProperty(cx, global, cx->names().Intl, IntlValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
{
|
||||
if (!JSObject::defineProperty(cx, global, cx->names().Intl, IntlValue, nullptr, nullptr, 0))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!JS_DefineFunctions(cx, Intl, intl_static_methods))
|
||||
return nullptr;
|
||||
|
|
|
@ -555,38 +555,30 @@ js::CreateUserSizeAndAlignmentProperties(JSContext *cx, HandleTypeDescr descr)
|
|||
if (descr->transparent()) {
|
||||
// byteLength
|
||||
RootedValue typeByteLength(cx, Int32Value(descr->size()));
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteLength,
|
||||
typeByteLength,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteLength, typeByteLength,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// byteAlignment
|
||||
RootedValue typeByteAlignment(cx, Int32Value(descr->alignment()));
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteAlignment,
|
||||
typeByteAlignment,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteAlignment, typeByteAlignment,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// byteLength
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteLength,
|
||||
UndefinedHandleValue,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteLength, UndefinedHandleValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// byteAlignment
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteAlignment,
|
||||
UndefinedHandleValue,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().byteAlignment, UndefinedHandleValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -620,16 +612,18 @@ ArrayMetaTypeDescr::create(JSContext *cx,
|
|||
obj->initReservedSlot(JS_DESCR_SLOT_ARRAY_LENGTH, Int32Value(length));
|
||||
|
||||
RootedValue elementTypeVal(cx, ObjectValue(*elementType));
|
||||
if (!JSObject::defineProperty(cx, obj, cx->names().elementType,
|
||||
elementTypeVal, nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, obj, cx->names().elementType, elementTypeVal,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RootedValue lengthValue(cx, NumberValue(length));
|
||||
if (!JSObject::defineProperty(cx, obj, cx->names().length,
|
||||
lengthValue, nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, obj, cx->names().length, lengthValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!CreateUserSizeAndAlignmentProperties(cx, obj))
|
||||
return nullptr;
|
||||
|
@ -976,16 +970,14 @@ StructMetaTypeDescr::create(JSContext *cx,
|
|||
if (!JSObject::freeze(cx, userFieldTypes))
|
||||
return nullptr;
|
||||
RootedValue userFieldOffsetsValue(cx, ObjectValue(*userFieldOffsets));
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().fieldOffsets,
|
||||
userFieldOffsetsValue, nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().fieldOffsets, userFieldOffsetsValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
RootedValue userFieldTypesValue(cx, ObjectValue(*userFieldTypes));
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().fieldTypes,
|
||||
userFieldTypesValue, nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, descr, cx->names().fieldTypes, userFieldTypesValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -1243,11 +1235,11 @@ DefineMetaTypeDescr(JSContext *cx,
|
|||
return nullptr;
|
||||
|
||||
RootedValue protoProtoValue(cx, ObjectValue(*protoProto));
|
||||
if (!JSObject::defineProperty(cx, proto, cx->names().prototype,
|
||||
protoProtoValue,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, proto, cx->names().prototype, protoProtoValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Create ctor itself
|
||||
|
||||
|
@ -1317,11 +1309,11 @@ GlobalObject::initTypedObjectModule(JSContext *cx, Handle<GlobalObject*> global)
|
|||
return false;
|
||||
|
||||
RootedValue arrayTypeValue(cx, ObjectValue(*arrayType));
|
||||
if (!JSObject::defineProperty(cx, module, cx->names().ArrayType,
|
||||
arrayTypeValue,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, module, cx->names().ArrayType, arrayTypeValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// StructType.
|
||||
|
||||
|
@ -1332,19 +1324,17 @@ GlobalObject::initTypedObjectModule(JSContext *cx, Handle<GlobalObject*> global)
|
|||
return false;
|
||||
|
||||
RootedValue structTypeValue(cx, ObjectValue(*structType));
|
||||
if (!JSObject::defineProperty(cx, module, cx->names().StructType,
|
||||
structTypeValue,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
if (!JSObject::defineProperty(cx, module, cx->names().StructType, structTypeValue,
|
||||
nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Everything is setup, install module on the global object:
|
||||
RootedValue moduleValue(cx, ObjectValue(*module));
|
||||
global->setConstructor(JSProto_TypedObject, moduleValue);
|
||||
if (!JSObject::defineProperty(cx, global, cx->names().TypedObject,
|
||||
moduleValue,
|
||||
nullptr, nullptr,
|
||||
0))
|
||||
if (!JSObject::defineProperty(cx, global, cx->names().TypedObject, moduleValue,
|
||||
nullptr, nullptr, 0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1252,8 +1252,7 @@ JS_ResolveStandardClass(JSContext *cx, HandleObject obj, HandleId id, bool *reso
|
|||
if (idstr == undefinedAtom) {
|
||||
*resolved = true;
|
||||
return JSObject::defineProperty(cx, obj, undefinedAtom->asPropertyName(),
|
||||
UndefinedHandleValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
UndefinedHandleValue, nullptr, nullptr,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY);
|
||||
}
|
||||
|
||||
|
@ -2862,6 +2861,19 @@ DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, HandleValue val
|
|||
? JS_FUNC_TO_DATA_PTR(JSObject *, setter)
|
||||
: nullptr);
|
||||
|
||||
// In most places throughout the engine, a property with null getter and
|
||||
// not JSPROP_GETTER/SETTER/SHARED has no getter, and the same for setters:
|
||||
// it's just a plain old data property. However the JS_Define* APIs use
|
||||
// null getter and setter to mean "default to the Class getProperty and
|
||||
// setProperty ops".
|
||||
if (!getter)
|
||||
getter = obj->getClass()->getProperty;
|
||||
if (!setter)
|
||||
setter = obj->getClass()->setProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
return JSObject::defineGeneric(cx, obj, id, value, getter, setter, attrs);
|
||||
}
|
||||
|
||||
|
|
|
@ -463,8 +463,19 @@ static bool
|
|||
array_length_setter(JSContext *cx, HandleObject obj, HandleId id, bool strict, MutableHandleValue vp)
|
||||
{
|
||||
if (!obj->is<ArrayObject>()) {
|
||||
// This array .length property was found on the prototype
|
||||
// chain. Ideally the setter should not have been called, but since
|
||||
// we're here, do an impression of SetPropertyByDefining.
|
||||
const Class *clasp = obj->getClass();
|
||||
JSPropertyOp getter = clasp->getProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
JSStrictPropertyOp setter = clasp->setProperty;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
|
||||
return JSObject::defineProperty(cx, obj, cx->names().length, vp,
|
||||
nullptr, nullptr, JSPROP_ENUMERATE);
|
||||
getter, setter, JSPROP_ENUMERATE);
|
||||
}
|
||||
|
||||
Rooted<ArrayObject*> arr(cx, &obj->as<ArrayObject>());
|
||||
|
|
|
@ -160,11 +160,8 @@ js_InitBooleanClass(JSContext *cx, HandleObject obj)
|
|||
return nullptr;
|
||||
|
||||
RootedValue value(cx, ObjectValue(*valueOf));
|
||||
if (!JSObject::defineProperty(cx, booleanProto, valueOfName, value,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
{
|
||||
if (!JSObject::defineProperty(cx, booleanProto, valueOfName, value, nullptr, nullptr, 0))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!GlobalObject::initBuiltinConstructor(cx, global, JSProto_Boolean, ctor, booleanProto))
|
||||
return nullptr;
|
||||
|
|
|
@ -508,11 +508,8 @@ ErrorObject::createProto(JSContext *cx, JSProtoKey key)
|
|||
// instance properties.
|
||||
RootedPropertyName name(cx, ClassName(key, cx));
|
||||
RootedValue nameValue(cx, StringValue(name));
|
||||
if (!JSObject::defineProperty(cx, err, cx->names().name, nameValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
{
|
||||
if (!JSObject::defineProperty(cx, err, cx->names().name, nameValue, nullptr, nullptr, 0))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return errorProto;
|
||||
}
|
||||
|
|
|
@ -419,8 +419,7 @@ ResolveInterpretedFunctionPrototype(JSContext *cx, HandleObject obj)
|
|||
// Per ES5 15.3.5.2 a user-defined function's .prototype property is
|
||||
// initially non-configurable, non-enumerable, and writable.
|
||||
RootedValue protoVal(cx, ObjectValue(*proto));
|
||||
if (!JSObject::defineProperty(cx, obj, cx->names().prototype,
|
||||
protoVal, JS_PropertyStub, JS_StrictPropertyStub,
|
||||
if (!JSObject::defineProperty(cx, obj, cx->names().prototype, protoVal, nullptr, nullptr,
|
||||
JSPROP_PERMANENT))
|
||||
{
|
||||
return nullptr;
|
||||
|
@ -432,8 +431,8 @@ ResolveInterpretedFunctionPrototype(JSContext *cx, HandleObject obj)
|
|||
// back with a .constructor.
|
||||
if (!isStarGenerator) {
|
||||
RootedValue objVal(cx, ObjectValue(*obj));
|
||||
if (!JSObject::defineProperty(cx, proto, cx->names().constructor,
|
||||
objVal, JS_PropertyStub, JS_StrictPropertyStub, 0))
|
||||
if (!JSObject::defineProperty(cx, proto, cx->names().constructor, objVal, nullptr, nullptr,
|
||||
0))
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -2120,11 +2119,15 @@ js::DefineFunction(JSContext *cx, HandleObject obj, HandleId id, Native native,
|
|||
* for more on this.
|
||||
*/
|
||||
flags &= ~JSFUN_STUB_GSOPS;
|
||||
gop = JS_PropertyStub;
|
||||
sop = JS_StrictPropertyStub;
|
||||
} else {
|
||||
gop = nullptr;
|
||||
sop = nullptr;
|
||||
} else {
|
||||
gop = obj->getClass()->getProperty;
|
||||
sop = obj->getClass()->setProperty;
|
||||
if (gop == JS_PropertyStub)
|
||||
gop = nullptr;
|
||||
if (sop == JS_StrictPropertyStub)
|
||||
sop = nullptr;
|
||||
}
|
||||
|
||||
JSFunction::Flags funFlags;
|
||||
|
|
|
@ -2426,8 +2426,7 @@ DefineStandardSlot(JSContext *cx, HandleObject obj, JSProtoKey key, JSAtom *atom
|
|||
}
|
||||
}
|
||||
|
||||
named = JSObject::defineGeneric(cx, obj, id,
|
||||
v, JS_PropertyStub, JS_StrictPropertyStub, attrs);
|
||||
named = JSObject::defineGeneric(cx, obj, id, v, nullptr, nullptr, attrs);
|
||||
return named;
|
||||
}
|
||||
|
||||
|
@ -2887,22 +2886,16 @@ JSObject::defineGeneric(ExclusiveContext *cx, HandleObject obj,
|
|||
HandleId id, HandleValue value,
|
||||
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs)
|
||||
{
|
||||
MOZ_ASSERT(getter != JS_PropertyStub);
|
||||
MOZ_ASSERT(setter != JS_StrictPropertyStub);
|
||||
MOZ_ASSERT(!(attrs & JSPROP_PROPOP_ACCESSORS));
|
||||
|
||||
js::DefineGenericOp op = obj->getOps()->defineGeneric;
|
||||
if (op) {
|
||||
if (!cx->shouldBeJSContext())
|
||||
return false;
|
||||
return op(cx->asJSContext(), obj, id, value, getter, setter, attrs);
|
||||
}
|
||||
|
||||
if (getter == nullptr)
|
||||
getter = obj->getClass()->getProperty;
|
||||
if (setter == nullptr)
|
||||
setter = obj->getClass()->setProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
return baseops::DefineGeneric(cx, obj.as<NativeObject>(), id, value, getter, setter, attrs);
|
||||
}
|
||||
|
||||
|
@ -2920,21 +2913,15 @@ JSObject::defineElement(ExclusiveContext *cx, HandleObject obj,
|
|||
uint32_t index, HandleValue value,
|
||||
JSPropertyOp getter, JSStrictPropertyOp setter, unsigned attrs)
|
||||
{
|
||||
MOZ_ASSERT(getter != JS_PropertyStub);
|
||||
MOZ_ASSERT(setter != JS_StrictPropertyStub);
|
||||
|
||||
js::DefineElementOp op = obj->getOps()->defineElement;
|
||||
if (op) {
|
||||
if (!cx->shouldBeJSContext())
|
||||
return false;
|
||||
return op(cx->asJSContext(), obj, index, value, getter, setter, attrs);
|
||||
}
|
||||
|
||||
if (!getter)
|
||||
getter = obj->getClass()->getProperty;
|
||||
if (!setter)
|
||||
setter = obj->getClass()->setProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
return baseops::DefineElement(cx, obj.as<NativeObject>(), index, value, getter, setter, attrs);
|
||||
}
|
||||
|
||||
|
|
|
@ -598,20 +598,20 @@ class JSObject : public js::gc::Cell
|
|||
|
||||
static bool defineGeneric(js::ExclusiveContext *cx, js::HandleObject obj,
|
||||
js::HandleId id, js::HandleValue value,
|
||||
JSPropertyOp getter = JS_PropertyStub,
|
||||
JSStrictPropertyOp setter = JS_StrictPropertyStub,
|
||||
JSPropertyOp getter = nullptr,
|
||||
JSStrictPropertyOp setter = nullptr,
|
||||
unsigned attrs = JSPROP_ENUMERATE);
|
||||
|
||||
static bool defineProperty(js::ExclusiveContext *cx, js::HandleObject obj,
|
||||
js::PropertyName *name, js::HandleValue value,
|
||||
JSPropertyOp getter = JS_PropertyStub,
|
||||
JSStrictPropertyOp setter = JS_StrictPropertyStub,
|
||||
JSPropertyOp getter = nullptr,
|
||||
JSStrictPropertyOp setter = nullptr,
|
||||
unsigned attrs = JSPROP_ENUMERATE);
|
||||
|
||||
static bool defineElement(js::ExclusiveContext *cx, js::HandleObject obj,
|
||||
uint32_t index, js::HandleValue value,
|
||||
JSPropertyOp getter = JS_PropertyStub,
|
||||
JSStrictPropertyOp setter = JS_StrictPropertyStub,
|
||||
JSPropertyOp getter = nullptr,
|
||||
JSStrictPropertyOp setter = nullptr,
|
||||
unsigned attrs = JSPROP_ENUMERATE);
|
||||
|
||||
static inline bool getGeneric(JSContext *cx, js::HandleObject obj, js::HandleObject receiver,
|
||||
|
|
|
@ -387,12 +387,8 @@ str_enumerate(JSContext *cx, HandleObject obj)
|
|||
if (!str1)
|
||||
return false;
|
||||
value.setString(str1);
|
||||
if (!JSObject::defineElement(cx, obj, i, value,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
STRING_ELEMENT_ATTRS))
|
||||
{
|
||||
if (!JSObject::defineElement(cx, obj, i, value, nullptr, nullptr, STRING_ELEMENT_ATTRS))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
|
@ -132,7 +132,17 @@ BaseProxyHandler::set(JSContext *cx, HandleObject proxy, HandleObject receiver,
|
|||
existingDescriptor
|
||||
? JSPROP_IGNORE_ENUMERATE | JSPROP_IGNORE_READONLY | JSPROP_IGNORE_PERMANENT
|
||||
: JSPROP_ENUMERATE;
|
||||
return JSObject::defineGeneric(cx, receiver, id, vp, nullptr, nullptr, attrs);
|
||||
|
||||
// A very old nonstandard SpiderMonkey extension: default to the Class
|
||||
// getter and setter ops.
|
||||
const Class *clasp = receiver->getClass();
|
||||
PropertyOp getter = clasp->getProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
setter = clasp->setProperty;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
return JSObject::defineGeneric(cx, receiver, id, vp, getter, setter, attrs);
|
||||
}
|
||||
|
||||
// Step 6.
|
||||
|
@ -153,43 +163,18 @@ js::SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handle
|
|||
bool descIsOwn, bool strict, MutableHandleValue vp)
|
||||
{
|
||||
/* The control-flow here differs from ::get() because of the fall-through case below. */
|
||||
if (descIsOwn) {
|
||||
MOZ_ASSERT(desc.object());
|
||||
|
||||
// Check for read-only properties.
|
||||
if (desc.isReadonly())
|
||||
return strict ? Throw(cx, id, JSMSG_READ_ONLY) : true;
|
||||
if (!desc.setter()) {
|
||||
// Be wary of the odd explicit undefined setter case possible through
|
||||
// Object.defineProperty.
|
||||
if (!desc.hasSetterObject())
|
||||
desc.setSetter(JS_StrictPropertyStub);
|
||||
} else if (desc.hasSetterObject() || desc.setter() != JS_StrictPropertyStub) {
|
||||
if (!CallSetter(cx, receiver, id, desc.setter(), desc.attributes(), strict, vp))
|
||||
return false;
|
||||
if (!proxy->is<ProxyObject>() || proxy->as<ProxyObject>().handler() != handler)
|
||||
return true;
|
||||
if (desc.isShared())
|
||||
return true;
|
||||
}
|
||||
if (!desc.getter()) {
|
||||
// Same as above for the null setter case.
|
||||
if (!desc.hasGetterObject())
|
||||
desc.setGetter(JS_PropertyStub);
|
||||
}
|
||||
desc.value().set(vp.get());
|
||||
return handler->defineProperty(cx, receiver, id, desc);
|
||||
}
|
||||
MOZ_ASSERT_IF(descIsOwn, desc.object());
|
||||
if (desc.object()) {
|
||||
// Check for read-only properties.
|
||||
if (desc.isReadonly())
|
||||
return strict ? Throw(cx, id, JSMSG_CANT_REDEFINE_PROP) : true;
|
||||
if (!desc.setter()) {
|
||||
// Be wary of the odd explicit undefined setter case possible through
|
||||
// Object.defineProperty.
|
||||
if (!desc.hasSetterObject())
|
||||
desc.setSetter(JS_StrictPropertyStub);
|
||||
} else if (desc.hasSetterObject() || desc.setter() != JS_StrictPropertyStub) {
|
||||
if (desc.isReadonly()) {
|
||||
if (strict)
|
||||
return Throw(cx, id, descIsOwn ? JSMSG_READ_ONLY : JSMSG_CANT_REDEFINE_PROP);
|
||||
return true;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(desc.getter() != JS_PropertyStub);
|
||||
MOZ_ASSERT(desc.setter() != JS_StrictPropertyStub);
|
||||
if (desc.hasSetterObject() || desc.setter()) {
|
||||
if (!CallSetter(cx, receiver, id, desc.setter(), desc.attributes(), strict, vp))
|
||||
return false;
|
||||
if (!proxy->is<ProxyObject>() || proxy->as<ProxyObject>().handler() != handler)
|
||||
|
@ -197,12 +182,10 @@ js::SetPropertyIgnoringNamedGetter(JSContext *cx, const BaseProxyHandler *handle
|
|||
if (desc.isShared())
|
||||
return true;
|
||||
}
|
||||
if (!desc.getter()) {
|
||||
// Same as above for the null setter case.
|
||||
if (!desc.hasGetterObject())
|
||||
desc.setGetter(JS_PropertyStub);
|
||||
}
|
||||
desc.value().set(vp.get());
|
||||
|
||||
if (descIsOwn)
|
||||
return handler->defineProperty(cx, receiver, id, desc);
|
||||
return JSObject::defineGeneric(cx, receiver, id, desc.value(),
|
||||
desc.getter(), desc.setter(), desc.attributes());
|
||||
}
|
||||
|
|
|
@ -352,7 +352,14 @@ Proxy::set(JSContext *cx, HandleObject proxy, HandleObject receiver, HandleId id
|
|||
(desc.object() == proxy)
|
||||
? JSPROP_IGNORE_ENUMERATE | JSPROP_IGNORE_READONLY | JSPROP_IGNORE_PERMANENT
|
||||
: JSPROP_ENUMERATE;
|
||||
return JSObject::defineGeneric(cx, receiver, id, vp, nullptr, nullptr, attrs);
|
||||
const Class *clasp = receiver->getClass();
|
||||
JSPropertyOp getter = clasp->getProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
JSStrictPropertyOp setter = clasp->setProperty;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
return JSObject::defineGeneric(cx, receiver, id, vp, getter, setter, attrs);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -453,7 +453,7 @@ class ByJSType {
|
|||
|
||||
RootedValue otherReport(cx);
|
||||
if (!other.report(census, &otherReport) ||
|
||||
!JSObject::defineProperty(cx, obj, cx->names().other, otherReport))
|
||||
!JSObject::defineProperty(cx, obj, cx->names().other, otherReport))
|
||||
return false;
|
||||
|
||||
report.setObject(*obj);
|
||||
|
|
|
@ -279,7 +279,7 @@ GlobalObject::initStandardClasses(JSContext *cx, Handle<GlobalObject*> global)
|
|||
{
|
||||
/* Define a top-level property 'undefined' with the undefined value. */
|
||||
if (!JSObject::defineProperty(cx, global, cx->names().undefined, UndefinedHandleValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -326,8 +326,7 @@ GlobalObject::initSelfHostingBuiltins(JSContext *cx, Handle<GlobalObject*> globa
|
|||
{
|
||||
// Define a top-level property 'undefined' with the undefined value.
|
||||
if (!JSObject::defineProperty(cx, global, cx->names().undefined, UndefinedHandleValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -435,11 +434,10 @@ js::LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor_, JSObject *proto_
|
|||
RootedValue protoVal(cx, ObjectValue(*proto));
|
||||
RootedValue ctorVal(cx, ObjectValue(*ctor));
|
||||
|
||||
return JSObject::defineProperty(cx, ctor, cx->names().prototype,
|
||||
protoVal, JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY) &&
|
||||
JSObject::defineProperty(cx, proto, cx->names().constructor,
|
||||
ctorVal, JS_PropertyStub, JS_StrictPropertyStub, 0);
|
||||
return JSObject::defineProperty(cx, ctor, cx->names().prototype, protoVal,
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY) &&
|
||||
JSObject::defineProperty(cx, proto, cx->names().constructor, ctorVal,
|
||||
nullptr, nullptr, 0);
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -346,8 +346,9 @@ DefVarOrConstOperation(JSContext *cx, HandleObject varobj, HandlePropertyName dn
|
|||
|
||||
/* Steps 8c, 8d. */
|
||||
if (!prop || (obj2 != varobj && varobj->is<GlobalObject>())) {
|
||||
if (!JSObject::defineProperty(cx, varobj, dn, UndefinedHandleValue, JS_PropertyStub,
|
||||
JS_StrictPropertyStub, attrs)) {
|
||||
if (!JSObject::defineProperty(cx, varobj, dn, UndefinedHandleValue, nullptr, nullptr,
|
||||
attrs))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
} else if (attrs & JSPROP_READONLY) {
|
||||
|
@ -557,6 +558,8 @@ static MOZ_ALWAYS_INLINE bool
|
|||
InitElemOperation(JSContext *cx, HandleObject obj, HandleValue idval, HandleValue val)
|
||||
{
|
||||
MOZ_ASSERT(!val.isMagic(JS_ELEMENTS_HOLE));
|
||||
MOZ_ASSERT(obj->getClass()->getProperty == JS_PropertyStub);
|
||||
MOZ_ASSERT(obj->getClass()->setProperty == JS_StrictPropertyStub);
|
||||
|
||||
RootedId id(cx);
|
||||
if (!ValueToId<CanGC>(cx, idval, &id))
|
||||
|
|
|
@ -3699,18 +3699,14 @@ js::DefFunOperation(JSContext *cx, HandleScript script, HandleObject scopeChain,
|
|||
: JSPROP_ENUMERATE | JSPROP_PERMANENT;
|
||||
|
||||
/* Steps 5d, 5f. */
|
||||
if (!shape || pobj != parent) {
|
||||
return JSObject::defineProperty(cx, parent, name, rval, JS_PropertyStub,
|
||||
JS_StrictPropertyStub, attrs);
|
||||
}
|
||||
if (!shape || pobj != parent)
|
||||
return JSObject::defineProperty(cx, parent, name, rval, nullptr, nullptr, attrs);
|
||||
|
||||
/* Step 5e. */
|
||||
MOZ_ASSERT(parent->isNative());
|
||||
if (parent->is<GlobalObject>()) {
|
||||
if (shape->configurable()) {
|
||||
return JSObject::defineProperty(cx, parent, name, rval, JS_PropertyStub,
|
||||
JS_StrictPropertyStub, attrs);
|
||||
}
|
||||
if (shape->configurable())
|
||||
return JSObject::defineProperty(cx, parent, name, rval, nullptr, nullptr, attrs);
|
||||
|
||||
if (shape->isAccessorDescriptor() || !shape->writable() || !shape->enumerable()) {
|
||||
JSAutoByteString bytes;
|
||||
|
@ -3959,11 +3955,11 @@ js::InitGetterSetterOperation(JSContext *cx, jsbytecode *pc, HandleObject obj, H
|
|||
|
||||
if (op == JSOP_INITPROP_GETTER || op == JSOP_INITELEM_GETTER) {
|
||||
getter = CastAsPropertyOp(val);
|
||||
setter = JS_StrictPropertyStub;
|
||||
setter = nullptr;
|
||||
attrs |= JSPROP_GETTER;
|
||||
} else {
|
||||
MOZ_ASSERT(op == JSOP_INITPROP_SETTER || op == JSOP_INITELEM_SETTER);
|
||||
getter = JS_PropertyStub;
|
||||
getter = nullptr;
|
||||
setter = CastAsStrictPropertyOp(val);
|
||||
attrs |= JSPROP_SETTER;
|
||||
}
|
||||
|
|
|
@ -396,8 +396,7 @@ SpreadCallOperation(JSContext *cx, HandleScript script, jsbytecode *pc, HandleVa
|
|||
inline bool
|
||||
SetConstOperation(JSContext *cx, HandleObject varobj, HandlePropertyName name, HandleValue rval)
|
||||
{
|
||||
return JSObject::defineProperty(cx, varobj, name, rval,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
return JSObject::defineProperty(cx, varobj, name, rval, nullptr, nullptr,
|
||||
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY);
|
||||
}
|
||||
|
||||
|
|
|
@ -2025,19 +2025,19 @@ SetPropertyByDefining(typename ExecutionModeTraits<mode>::ContextType cxArg,
|
|||
}
|
||||
|
||||
// Define the new data property.
|
||||
if (!receiver->is<NativeObject>()) {
|
||||
if (mode == ParallelExecution)
|
||||
return false;
|
||||
return JSObject::defineGeneric(cxArg->asJSContext(), receiver, id, v,
|
||||
clasp->getProperty, clasp->setProperty, JSPROP_ENUMERATE);
|
||||
}
|
||||
Rooted<NativeObject*> nativeReceiver(cxArg, &receiver->as<NativeObject>());
|
||||
JSPropertyOp getter = clasp->getProperty;
|
||||
if (getter == JS_PropertyStub)
|
||||
getter = nullptr;
|
||||
JSStrictPropertyOp setter = clasp->setProperty;
|
||||
if (setter == JS_StrictPropertyStub)
|
||||
setter = nullptr;
|
||||
if (!receiver->is<NativeObject>()) {
|
||||
if (mode == ParallelExecution)
|
||||
return false;
|
||||
return JSObject::defineGeneric(cxArg->asJSContext(), receiver, id, v, getter, setter,
|
||||
JSPROP_ENUMERATE);
|
||||
}
|
||||
Rooted<NativeObject*> nativeReceiver(cxArg, &receiver->as<NativeObject>());
|
||||
return DefinePropertyOrElement<mode>(cxArg, nativeReceiver, id, getter, setter,
|
||||
JSPROP_ENUMERATE, v, true, strict);
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ intrinsic_MakeConstructible(JSContext *cx, unsigned argc, Value *vp)
|
|||
// correctly, it must be enumerable.
|
||||
RootedObject ctor(cx, &args[0].toObject());
|
||||
if (!JSObject::defineProperty(cx, ctor, cx->names().prototype, args[1],
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
nullptr, nullptr,
|
||||
JSPROP_READONLY | JSPROP_ENUMERATE | JSPROP_PERMANENT))
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -748,14 +748,10 @@ SharedTypedArrayObjectTemplate<NativeType>::FinishClassInit(JSContext *cx,
|
|||
{
|
||||
RootedValue bytesValue(cx, Int32Value(BYTES_PER_ELEMENT));
|
||||
|
||||
if (!JSObject::defineProperty(cx, ctor,
|
||||
cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY) ||
|
||||
!JSObject::defineProperty(cx, proto,
|
||||
cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
if (!JSObject::defineProperty(cx, ctor, cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY) ||
|
||||
!JSObject::defineProperty(cx, proto, cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -242,14 +242,10 @@ class TypedArrayObjectTemplate : public TypedArrayObject
|
|||
finishClassInit(JSContext *cx, HandleObject ctor, HandleObject proto)
|
||||
{
|
||||
RootedValue bytesValue(cx, Int32Value(BYTES_PER_ELEMENT));
|
||||
if (!JSObject::defineProperty(cx, ctor,
|
||||
cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY) ||
|
||||
!JSObject::defineProperty(cx, proto,
|
||||
cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
JS_PropertyStub, JS_StrictPropertyStub,
|
||||
JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
if (!JSObject::defineProperty(cx, ctor, cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY) ||
|
||||
!JSObject::defineProperty(cx, proto, cx->names().BYTES_PER_ELEMENT, bytesValue,
|
||||
nullptr, nullptr, JSPROP_PERMANENT | JSPROP_READONLY))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче