Backed out changeset 94f14d6b26d5 (bug 1125624)

This commit is contained in:
Carsten "Tomcat" Book 2015-06-17 11:02:59 +02:00
parent ec89b35efa
commit e26e0bab77
13 changed files with 78 additions and 31 deletions

View File

@ -181,12 +181,12 @@ DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::
return result.succeed();
}
JS::Rooted<JSObject*> expando(cx, EnsureExpandoObject(cx, proxy));
JSObject* expando = EnsureExpandoObject(cx, proxy);
if (!expando) {
return false;
}
if (!JS_DefinePropertyById(cx, expando, id, desc, result)) {
if (!js::DefineOwnProperty(cx, expando, id, desc, result)) {
return false;
}
*defined = true;

View File

@ -189,7 +189,7 @@ WrapperAnswer::RecvDefineProperty(const ObjectId& objId, const JSIDVariant& idVa
return fail(jsapi, rs);
ObjectOpResult success;
if (!JS_DefinePropertyById(cx, obj, id, desc, success))
if (!js::DefineOwnProperty(cx, obj, id, desc, success))
return fail(jsapi, rs);
return ok(rs, success);
}

View File

@ -832,7 +832,7 @@ js::obj_defineProperty(JSContext* cx, unsigned argc, Value* vp)
return false;
// Steps 6-8.
if (!DefineProperty(cx, obj, id, desc))
if (!StandardDefineProperty(cx, obj, id, desc))
return false;
args.rval().setObject(*obj);
return true;

View File

@ -1200,6 +1200,23 @@ js::GetObjectMetadata(JSObject* obj)
return nullptr;
}
JS_FRIEND_API(bool)
js::DefineOwnProperty(JSContext* cx, JSObject* objArg, jsid idArg,
JS::Handle<js::PropertyDescriptor> descriptor, ObjectOpResult& result)
{
RootedObject obj(cx, objArg);
RootedId id(cx, idArg);
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, id, descriptor.value());
if (descriptor.hasGetterObject())
assertSameCompartment(cx, descriptor.getterObject());
if (descriptor.hasSetterObject())
assertSameCompartment(cx, descriptor.setterObject());
return StandardDefineProperty(cx, obj, id, descriptor, result);
}
JS_FRIEND_API(bool)
js::ReportIsNotFunction(JSContext* cx, HandleValue v)
{

View File

@ -2812,6 +2812,10 @@ GetFirstSubsumedSavedFrame(JSContext* cx, JS::HandleObject savedFrame);
extern JS_FRIEND_API(bool)
ReportIsNotFunction(JSContext* cx, JS::HandleValue v);
extern JS_FRIEND_API(bool)
DefineOwnProperty(JSContext* cx, JSObject* objArg, jsid idArg,
JS::Handle<JSPropertyDescriptor> descriptor, JS::ObjectOpResult& result);
extern JS_FRIEND_API(JSObject*)
ConvertArgsToArray(JSContext* cx, const JS::CallArgs& args);

View File

@ -274,7 +274,23 @@ js::Throw(JSContext* cx, JSObject* obj, unsigned errorNumber)
}
/*** PropertyDescriptor operations and DefineProperties ******************************************/
/*** Standard-compliant property definition (used by Object.defineProperty) **********************/
bool
js::StandardDefineProperty(JSContext* cx, HandleObject obj, HandleId id,
Handle<PropertyDescriptor> desc, ObjectOpResult& result)
{
return DefineProperty(cx, obj, id, desc, result);
}
bool
js::StandardDefineProperty(JSContext* cx, HandleObject obj, HandleId id,
Handle<PropertyDescriptor> desc)
{
ObjectOpResult success;
return DefineProperty(cx, obj, id, desc, success) &&
success.checkStrict(cx, obj, id);
}
bool
CheckCallable(JSContext* cx, JSObject* obj, const char* fieldName)
@ -471,14 +487,13 @@ js::DefineProperties(JSContext* cx, HandleObject obj, HandleObject props)
return false;
for (size_t i = 0, len = ids.length(); i < len; i++) {
if (!DefineProperty(cx, obj, ids[i], descs[i]))
if (!StandardDefineProperty(cx, obj, ids[i], descs[i]))
return false;
}
return true;
}
/*** Seal and freeze *****************************************************************************/
static unsigned
@ -581,15 +596,15 @@ js::SetIntegrityLevel(JSContext* cx, HandleObject obj, IntegrityLevel level)
}
// 8.a.i-ii. / 9.a.iii.3-4
if (!DefineProperty(cx, obj, id, desc))
if (!StandardDefineProperty(cx, obj, id, desc))
return false;
}
}
// Ordinarily ArraySetLength handles this, but we're going behind its back
// right now, so we must do this manually. Neither the custom property
// tree mutations nor the DefineProperty call in the above code will do
// this for us.
// tree mutations nor the StandardDefineProperty call in the above code will
// do this for us.
//
// ArraySetLength also implements the capacity <= length invariant for
// arrays with non-writable length. We don't need to do anything special
@ -1095,7 +1110,7 @@ JS_CopyPropertyFrom(JSContext* cx, HandleId id, HandleObject target,
if (!cx->compartment()->wrap(cx, &desc))
return false;
return DefineProperty(cx, target, wrappedId, desc);
return StandardDefineProperty(cx, target, wrappedId, desc);
}
JS_FRIEND_API(bool)
@ -2598,14 +2613,6 @@ js::GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
return true;
}
bool
js::DefineProperty(JSContext* cx, HandleObject obj, HandleId id, Handle<PropertyDescriptor> desc)
{
ObjectOpResult result;
return DefineProperty(cx, obj, id, desc, result) &&
result.checkStrict(cx, obj, id);
}
bool
js::DefineProperty(JSContext* cx, HandleObject obj, HandleId id, Handle<PropertyDescriptor> desc,
ObjectOpResult& result)

View File

@ -749,7 +749,29 @@ extern bool
GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id,
MutableHandle<PropertyDescriptor> desc);
/* ES6 [[DefineOwnProperty]]. Define a property on obj. */
/*
* ES6 [[DefineOwnProperty]]. Define a property on obj.
*
* If obj is an array, this follows ES5 15.4.5.1.
* If obj is any other native object, this follows ES5 8.12.9.
* If obj is a proxy, this calls the proxy handler's defineProperty method.
* Otherwise, this reports an error and returns false.
*
* Both StandardDefineProperty functions hew close to the ES5 spec. Note that
* the DefineProperty functions do not enforce some invariants mandated by ES6.
*/
extern bool
StandardDefineProperty(JSContext* cx, HandleObject obj, HandleId id,
Handle<PropertyDescriptor> descriptor, ObjectOpResult& result);
/*
* Same as above except without the ObjectOpResult out-parameter. Throws a
* TypeError on failure.
*/
extern bool
StandardDefineProperty(JSContext* cx, HandleObject obj, HandleId id,
Handle<PropertyDescriptor> desc);
extern bool
DefineProperty(JSContext* cx, HandleObject obj, HandleId id,
Handle<PropertyDescriptor> desc, ObjectOpResult& result);
@ -770,9 +792,6 @@ DefineElement(ExclusiveContext* cx, HandleObject obj, uint32_t index, HandleValu
* When the 'result' out-param is omitted, the behavior is the same as above, except
* that any failure results in a TypeError.
*/
extern bool
DefineProperty(JSContext* cx, HandleObject obj, HandleId id, Handle<PropertyDescriptor> desc);
extern bool
DefineProperty(ExclusiveContext* cx, HandleObject obj, HandleId id, HandleValue value,
JSGetterOp getter = nullptr,

View File

@ -719,7 +719,7 @@ Walk(JSContext* cx, HandleObject holder, HandleId name, HandleValue reviver, Mut
/* Step 2a(iii)(3). The spec deliberately ignores strict failure. */
Rooted<PropertyDescriptor> desc(cx);
desc.setDataDescriptor(newElement, JSPROP_ENUMERATE);
if (!DefineProperty(cx, obj, id, desc, ignored))
if (!StandardDefineProperty(cx, obj, id, desc, ignored))
return false;
}
}
@ -747,7 +747,7 @@ Walk(JSContext* cx, HandleObject holder, HandleId name, HandleValue reviver, Mut
/* Step 2b(ii)(3). The spec deliberately ignores strict failure. */
Rooted<PropertyDescriptor> desc(cx);
desc.setDataDescriptor(newElement, JSPROP_ENUMERATE);
if (!DefineProperty(cx, obj, id, desc, ignored))
if (!StandardDefineProperty(cx, obj, id, desc, ignored))
return false;
}
}

View File

@ -39,7 +39,7 @@ DirectProxyHandler::defineProperty(JSContext* cx, HandleObject proxy, HandleId i
{
assertEnteredPolicy(cx, proxy, id, SET);
RootedObject target(cx, proxy->as<ProxyObject>().target());
return DefineProperty(cx, target, id, desc, result);
return StandardDefineProperty(cx, target, id, desc, result);
}
bool

View File

@ -548,7 +548,7 @@ ScriptedDirectProxyHandler::defineProperty(JSContext* cx, HandleObject proxy, Ha
// step 8
if (trap.isUndefined())
return DefineProperty(cx, target, id, desc, result);
return StandardDefineProperty(cx, target, id, desc, result);
// step 9
RootedValue descObj(cx);

View File

@ -7003,7 +7003,7 @@ DebuggerObject_defineProperty(JSContext* cx, unsigned argc, Value* vp)
return false;
ErrorCopier ec(ac);
if (!DefineProperty(cx, obj, id, desc))
if (!StandardDefineProperty(cx, obj, id, desc))
return false;
}
@ -7046,7 +7046,7 @@ DebuggerObject_defineProperties(JSContext* cx, unsigned argc, Value* vp)
ErrorCopier ec(ac);
for (size_t i = 0; i < n; i++) {
if (!DefineProperty(cx, obj, ids[i], descs[i]))
if (!StandardDefineProperty(cx, obj, ids[i], descs[i]))
return false;
}
}

View File

@ -349,7 +349,7 @@ js::intrinsic_DefineDataProperty(JSContext* cx, unsigned argc, Value* vp)
Rooted<PropertyDescriptor> desc(cx);
desc.setDataDescriptor(value, attrs);
if (!DefineProperty(cx, obj, id, desc))
if (!StandardDefineProperty(cx, obj, id, desc))
return false;
args.rval().setUndefined();

View File

@ -609,7 +609,7 @@ UnboxedPlainObject::convertToNative(JSContext* cx, JSObject* obj)
if (!GetOwnPropertyDescriptor(cx, nexpando, id, &desc))
return false;
ObjectOpResult result;
if (!DefineProperty(cx, nobj, id, desc, result))
if (!StandardDefineProperty(cx, nobj, id, desc, result))
return false;
MOZ_ASSERT(result.ok());
}