Bug 692039 - Split defineProperty into property and generic forms, and use them throughout the engine. r=bhackett

--HG--
extra : rebase_source : dce725d8771e2737f1a7059dc1698cc1b0814cd0
This commit is contained in:
Jeff Walden 2011-10-05 01:00:23 -07:00
parent 32f38cb2bb
commit 8b4270b28b
22 changed files with 204 additions and 126 deletions

View File

@ -4884,7 +4884,7 @@ JSParseNode::getConstantValue(JSContext *cx, bool strictChecks, Value *vp)
Value value;
if (!pn->getConstantValue(cx, strictChecks, &value))
return false;
if (!obj->defineProperty(cx, INT_TO_JSID(idx), value, NULL, NULL, JSPROP_ENUMERATE))
if (!obj->defineGeneric(cx, INT_TO_JSID(idx), value, NULL, NULL, JSPROP_ENUMERATE))
return false;
}
JS_ASSERT(idx == pn_count);
@ -4914,7 +4914,7 @@ JSParseNode::getConstantValue(JSContext *cx, bool strictChecks, Value *vp)
id = INT_TO_JSID(idvalue.toInt32());
else if (!js_InternNonIntElementId(cx, obj, idvalue, &id))
return false;
if (!obj->defineProperty(cx, id, value, NULL, NULL, JSPROP_ENUMERATE))
if (!obj->defineGeneric(cx, id, value, NULL, NULL, JSPROP_ENUMERATE))
return false;
} else {
JS_ASSERT(pnid->isKind(TOK_NAME) ||

View File

@ -1818,7 +1818,7 @@ JS_ResolveStandardClass(JSContext *cx, JSObject *obj, jsid id, JSBool *resolved)
atom = rt->atomState.typeAtoms[JSTYPE_VOID];
if (idstr == atom) {
*resolved = JS_TRUE;
return obj->defineProperty(cx, ATOM_TO_JSID(atom), UndefinedValue(),
return obj->defineProperty(cx, atom->asPropertyName(), UndefinedValue(),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT | JSPROP_READONLY);
}
@ -1889,7 +1889,6 @@ JS_PUBLIC_API(JSBool)
JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj)
{
JSRuntime *rt;
JSAtom *atom;
uintN i;
CHECK_REQUEST(cx);
@ -1900,9 +1899,9 @@ JS_EnumerateStandardClasses(JSContext *cx, JSObject *obj)
* Check whether we need to bind 'undefined' and define it if so.
* Since ES5 15.1.1.3 undefined can't be deleted.
*/
atom = rt->atomState.typeAtoms[JSTYPE_VOID];
if (!obj->nativeContains(cx, ATOM_TO_JSID(atom)) &&
!obj->defineProperty(cx, ATOM_TO_JSID(atom), UndefinedValue(),
PropertyName *name = rt->atomState.typeAtoms[JSTYPE_VOID];
if (!obj->nativeContains(cx, ATOM_TO_JSID(name)) &&
!obj->defineProperty(cx, name, UndefinedValue(),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT | JSPROP_READONLY)) {
return JS_FALSE;
@ -3500,7 +3499,7 @@ DefinePropertyById(JSContext *cx, JSObject *obj, jsid id, const Value &value,
return !!DefineNativeProperty(cx, obj, id, value, getter, setter,
attrs, flags, tinyid);
}
return obj->defineProperty(cx, id, value, getter, setter, attrs);
return obj->defineGeneric(cx, id, value, getter, setter, attrs);
}
JS_PUBLIC_API(JSBool)
@ -4862,8 +4861,8 @@ CompileUCFunctionForPrincipalsCommon(JSContext *cx, JSObject *obj,
}
if (obj && funAtom &&
!obj->defineProperty(cx, ATOM_TO_JSID(funAtom), ObjectValue(*fun),
NULL, NULL, JSPROP_ENUMERATE)) {
!obj->defineGeneric(cx, ATOM_TO_JSID(funAtom), ObjectValue(*fun),
NULL, NULL, JSPROP_ENUMERATE)) {
return NULL;
}

View File

@ -596,9 +596,8 @@ static JSBool
array_length_setter(JSContext *cx, JSObject *obj, jsid id, JSBool strict, Value *vp)
{
if (!obj->isArray()) {
jsid lengthId = ATOM_TO_JSID(cx->runtime->atomState.lengthAtom);
return obj->defineProperty(cx, lengthId, *vp, NULL, NULL, JSPROP_ENUMERATE);
return obj->defineProperty(cx, cx->runtime->atomState.lengthAtom, *vp,
NULL, NULL, JSPROP_ENUMERATE);
}
uint32 newlen;
@ -1005,12 +1004,9 @@ js_PrototypeHasIndexedProperties(JSContext *cx, JSObject *obj)
return JS_FALSE;
}
namespace js {
/* non-static for direct definition of array elements within the engine */
JSBool
array_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *value,
JSPropertyOp getter, StrictPropertyOp setter, uintN attrs)
static JSBool
array_defineGeneric(JSContext *cx, JSObject *obj, jsid id, const Value *value,
JSPropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
if (JSID_IS_ATOM(id, cx->runtime->atomState.lengthAtom))
return JS_TRUE;
@ -1043,6 +1039,15 @@ array_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *value,
return js_DefineProperty(cx, obj, id, value, getter, setter, attrs);
}
static JSBool
array_defineProperty(JSContext *cx, JSObject *obj, PropertyName *name, const Value *value,
JSPropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return array_defineGeneric(cx, obj, ATOM_TO_JSID(name), value, getter, setter, attrs);
}
namespace js {
/* non-static for direct definition of array elements within the engine */
JSBool
array_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *value,
@ -1088,7 +1093,7 @@ static JSBool
array_defineSpecial(JSContext *cx, JSObject *obj, SpecialId sid, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return array_defineProperty(cx, obj, SPECIALID_TO_JSID(sid), value, getter, setter, attrs);
return array_defineGeneric(cx, obj, SPECIALID_TO_JSID(sid), value, getter, setter, attrs);
}
static JSBool
@ -1260,7 +1265,7 @@ Class js::ArrayClass = {
array_lookupProperty,
array_lookupElement,
array_lookupSpecial,
array_defineProperty,
array_defineGeneric,
array_defineProperty,
array_defineElement,
array_defineSpecial,

View File

@ -173,8 +173,8 @@ js_SetLengthProperty(JSContext *cx, JSObject *obj, jsdouble length);
namespace js {
extern JSBool
array_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
array_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
extern JSBool
array_deleteElement(JSContext *cx, JSObject *obj, uint32 index, Value *rval, JSBool strict);

View File

@ -193,7 +193,7 @@ typedef JSBool
(* DefineGenericOp)(JSContext *cx, JSObject *obj, jsid id, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
typedef JSBool
(* DefinePropOp)(JSContext *cx, JSObject *obj, jsid id, const Value *value,
(* DefinePropOp)(JSContext *cx, JSObject *obj, PropertyName *name, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
typedef JSBool
(* DefineElementOp)(JSContext *cx, JSObject *obj, uint32 index, const Value *value,

View File

@ -876,7 +876,7 @@ JSStructuredCloneReader::read(Value *vp)
objs.popBack();
} else {
Value v;
if (!startRead(&v) || !obj->defineProperty(context(), id, v))
if (!startRead(&v) || !obj->defineGeneric(context(), id, v))
return false;
}
}

View File

@ -1451,10 +1451,10 @@ ResolveInterpretedFunctionPrototype(JSContext *cx, JSObject *obj)
* the prototype's .constructor property is configurable, non-enumerable,
* and writable.
*/
if (!obj->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.classPrototypeAtom),
if (!obj->defineProperty(cx, cx->runtime->atomState.classPrototypeAtom,
ObjectValue(*proto), JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT) ||
!proto->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.constructorAtom),
!proto->defineProperty(cx, cx->runtime->atomState.constructorAtom,
ObjectValue(*obj), JS_PropertyStub, JS_StrictPropertyStub, 0))
{
return NULL;
@ -2582,7 +2582,7 @@ js_DefineFunction(JSContext *cx, JSObject *obj, jsid id, Native native,
if (!wasDelegate && obj->isDelegate())
obj->clearDelegate();
if (!obj->defineProperty(cx, id, ObjectValue(*fun), gop, sop, attrs & ~JSFUN_FLAGS_MASK))
if (!obj->defineGeneric(cx, id, ObjectValue(*fun), gop, sop, attrs & ~JSFUN_FLAGS_MASK))
return NULL;
return fun;

View File

@ -2661,7 +2661,7 @@ BEGIN_CASE(JSOP_SETCONST)
LOAD_ATOM(0, atom);
JSObject &obj = regs.fp()->varObj();
const Value &ref = regs.sp[-1];
if (!obj.defineProperty(cx, ATOM_TO_JSID(atom), ref,
if (!obj.defineProperty(cx, atom->asPropertyName(), ref,
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY)) {
goto error;
@ -2677,9 +2677,9 @@ BEGIN_CASE(JSOP_ENUMCONSTELEM)
FETCH_OBJECT(cx, -2, obj);
jsid id;
FETCH_ELEMENT_ID(obj, -1, id);
if (!obj->defineProperty(cx, id, ref,
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY)) {
if (!obj->defineGeneric(cx, id, ref,
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY)) {
goto error;
}
regs.sp -= 3;
@ -4666,10 +4666,15 @@ BEGIN_CASE(JSOP_DEFFUN)
Value rval = ObjectValue(*obj);
do {
PropertyName *name = fun->atom->asPropertyName();
/* Steps 5d, 5f. */
if (!prop || pobj != parent) {
if (!parent->defineProperty(cx, id, rval, JS_PropertyStub, JS_StrictPropertyStub, attrs))
if (!parent->defineProperty(cx, name, rval,
JS_PropertyStub, JS_StrictPropertyStub, attrs))
{
goto error;
}
break;
}
@ -4678,8 +4683,11 @@ BEGIN_CASE(JSOP_DEFFUN)
Shape *shape = reinterpret_cast<Shape *>(prop);
if (parent->isGlobal()) {
if (shape->configurable()) {
if (!parent->defineProperty(cx, id, rval, JS_PropertyStub, JS_StrictPropertyStub, attrs))
if (!parent->defineProperty(cx, name, rval,
JS_PropertyStub, JS_StrictPropertyStub, attrs))
{
goto error;
}
break;
}
@ -4730,7 +4738,9 @@ BEGIN_CASE(JSOP_DEFFUN_FC)
if ((attrs == JSPROP_ENUMERATE)
? !parent.setProperty(cx, id, &rval, script->strictModeCode)
: !parent.defineProperty(cx, id, rval, JS_PropertyStub, JS_StrictPropertyStub, attrs)) {
: !parent.defineProperty(cx, fun->atom->asPropertyName(), rval,
JS_PropertyStub, JS_StrictPropertyStub, attrs))
{
goto error;
}
}
@ -5020,7 +5030,7 @@ BEGIN_CASE(JSOP_SETTER)
if (!CheckRedeclaration(cx, obj, id, attrs))
goto error;
if (!obj->defineProperty(cx, id, UndefinedValue(), getter, setter, attrs))
if (!obj->defineGeneric(cx, id, UndefinedValue(), getter, setter, attrs))
goto error;
regs.sp += i;
@ -5209,7 +5219,7 @@ BEGIN_CASE(JSOP_INITELEM)
goto error;
}
} else {
if (!obj->defineProperty(cx, id, rref, NULL, NULL, JSPROP_ENUMERATE))
if (!obj->defineGeneric(cx, id, rref, NULL, NULL, JSPROP_ENUMERATE))
goto error;
}
regs.sp -= 2;
@ -5243,7 +5253,7 @@ BEGIN_CASE(JSOP_DEFSHARP)
JSMSG_BAD_SHARP_DEF, numBuf);
goto error;
}
if (!obj->defineProperty(cx, id, rref, NULL, NULL, JSPROP_ENUMERATE))
if (!obj->defineGeneric(cx, id, rref, NULL, NULL, JSPROP_ENUMERATE))
goto error;
}
END_CASE(JSOP_DEFSHARP)

View File

@ -1639,8 +1639,8 @@ js::obj_defineGetter(JSContext *cx, uintN argc, Value *vp)
if (!CheckAccess(cx, obj, id, JSACC_WATCH, &junk, &attrs))
return JS_FALSE;
args.rval().setUndefined();
return obj->defineProperty(cx, id, UndefinedValue(), getter, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_GETTER | JSPROP_SHARED);
return obj->defineGeneric(cx, id, UndefinedValue(), getter, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_GETTER | JSPROP_SHARED);
}
JS_FRIEND_API(JSBool)
@ -1673,8 +1673,8 @@ js::obj_defineSetter(JSContext *cx, uintN argc, Value *vp)
if (!CheckAccess(cx, obj, id, JSACC_WATCH, &junk, &attrs))
return JS_FALSE;
args.rval().setUndefined();
return obj->defineProperty(cx, id, UndefinedValue(), JS_PropertyStub, setter,
JSPROP_ENUMERATE | JSPROP_SETTER | JSPROP_SHARED);
return obj->defineGeneric(cx, id, UndefinedValue(), JS_PropertyStub, setter,
JSPROP_ENUMERATE | JSPROP_SETTER | JSPROP_SHARED);
}
static JSBool
@ -1808,26 +1808,20 @@ PropDesc::makeObject(JSContext *cx)
const JSAtomState &atomState = cx->runtime->atomState;
if ((hasConfigurable &&
!obj->defineProperty(cx, ATOM_TO_JSID(atomState.configurableAtom),
BooleanValue((attrs & JSPROP_PERMANENT) == 0),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE)) ||
!obj->defineProperty(cx, atomState.configurableAtom,
BooleanValue((attrs & JSPROP_PERMANENT) == 0))) ||
(hasEnumerable &&
!obj->defineProperty(cx, ATOM_TO_JSID(atomState.enumerableAtom),
BooleanValue((attrs & JSPROP_ENUMERATE) != 0),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE)) ||
!obj->defineProperty(cx, atomState.enumerableAtom,
BooleanValue((attrs & JSPROP_ENUMERATE) != 0))) ||
(hasGet &&
!obj->defineProperty(cx, ATOM_TO_JSID(atomState.getAtom), get,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE)) ||
!obj->defineProperty(cx, atomState.getAtom, get)) ||
(hasSet &&
!obj->defineProperty(cx, ATOM_TO_JSID(atomState.setAtom), set,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE)) ||
!obj->defineProperty(cx, atomState.setAtom, set)) ||
(hasValue &&
!obj->defineProperty(cx, ATOM_TO_JSID(atomState.valueAtom), value,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE)) ||
!obj->defineProperty(cx, atomState.valueAtom, value)) ||
(hasWritable &&
!obj->defineProperty(cx, ATOM_TO_JSID(atomState.writableAtom),
BooleanValue((attrs & JSPROP_READONLY) == 0),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_ENUMERATE)))
!obj->defineProperty(cx, atomState.writableAtom,
BooleanValue((attrs & JSPROP_READONLY) == 0))))
{
return false;
}
@ -3721,7 +3715,7 @@ JS_CopyPropertiesFrom(JSContext *cx, JSObject *target, JSObject *obj)
Value v = shape->hasSlot() ? obj->getSlot(shape->slot) : UndefinedValue();
if (!cx->compartment->wrap(cx, &v))
return false;
if (!target->defineProperty(cx, shape->propid, v, getter, setter, attrs))
if (!target->defineGeneric(cx, shape->propid, v, getter, setter, attrs))
return false;
}
return true;
@ -4190,7 +4184,7 @@ DefineStandardSlot(JSContext *cx, JSObject *obj, JSProtoKey key, JSAtom *atom,
}
}
named = obj->defineProperty(cx, id, v, JS_PropertyStub, JS_StrictPropertyStub, attrs);
named = obj->defineGeneric(cx, id, v, JS_PropertyStub, JS_StrictPropertyStub, attrs);
return named;
}

View File

@ -1357,22 +1357,22 @@ struct JSObject : js::gc::Cell {
inline JSBool lookupElement(JSContext *cx, uint32 index, JSObject **objp, JSProperty **propp);
inline JSBool lookupSpecial(JSContext *cx, js::SpecialId sid, JSObject **objp, JSProperty **propp);
JSBool defineProperty(JSContext *cx, jsid id, const js::Value &value,
JSPropertyOp getter = JS_PropertyStub,
JSStrictPropertyOp setter = JS_StrictPropertyStub,
uintN attrs = JSPROP_ENUMERATE) {
js::DefinePropOp op = getOps()->defineProperty;
return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
}
JSBool defineElement(JSContext *cx, uint32 index, const js::Value &value,
JSPropertyOp getter = JS_PropertyStub,
JSStrictPropertyOp setter = JS_StrictPropertyStub,
uintN attrs = JSPROP_ENUMERATE)
{
js::DefineElementOp op = getOps()->defineElement;
return (op ? op : js_DefineElement)(cx, this, index, &value, getter, setter, attrs);
}
inline JSBool defineGeneric(JSContext *cx, jsid id, const js::Value &value,
JSPropertyOp getter = JS_PropertyStub,
JSStrictPropertyOp setter = JS_StrictPropertyStub,
uintN attrs = JSPROP_ENUMERATE);
inline JSBool defineProperty(JSContext *cx, js::PropertyName *name, const js::Value &value,
JSPropertyOp getter = JS_PropertyStub,
JSStrictPropertyOp setter = JS_StrictPropertyStub,
uintN attrs = JSPROP_ENUMERATE);
inline JSBool defineElement(JSContext *cx, uint32 index, const js::Value &value,
JSPropertyOp getter = JS_PropertyStub,
JSStrictPropertyOp setter = JS_StrictPropertyStub,
uintN attrs = JSPROP_ENUMERATE);
inline JSBool defineSpecial(JSContext *cx, js::SpecialId sid, const js::Value &value,
JSPropertyOp getter = JS_PropertyStub,
JSStrictPropertyOp setter = JS_StrictPropertyStub,
uintN attrs = JSPROP_ENUMERATE);
inline JSBool getGeneric(JSContext *cx, JSObject *receiver, jsid id, js::Value *vp);
inline JSBool getProperty(JSContext *cx, JSObject *receiver, js::PropertyName *name,

View File

@ -1156,6 +1156,44 @@ JSObject::lookupProperty(JSContext *cx, js::PropertyName *name, JSObject **objp,
return lookupGeneric(cx, ATOM_TO_JSID(name), objp, propp);
}
inline JSBool
JSObject::defineGeneric(JSContext *cx, jsid id, const js::Value &value,
JSPropertyOp getter /* = JS_PropertyStub */,
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
uintN attrs /* = JSPROP_ENUMERATE */)
{
js::DefineGenericOp op = getOps()->defineGeneric;
return (op ? op : js_DefineProperty)(cx, this, id, &value, getter, setter, attrs);
}
inline JSBool
JSObject::defineProperty(JSContext *cx, js::PropertyName *name, const js::Value &value,
JSPropertyOp getter /* = JS_PropertyStub */,
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
uintN attrs /* = JSPROP_ENUMERATE */)
{
return defineGeneric(cx, ATOM_TO_JSID(name), value, getter, setter, attrs);
}
inline JSBool
JSObject::defineElement(JSContext *cx, uint32 index, const js::Value &value,
JSPropertyOp getter /* = JS_PropertyStub */,
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
uintN attrs /* = JSPROP_ENUMERATE */)
{
js::DefineElementOp op = getOps()->defineElement;
return (op ? op : js_DefineElement)(cx, this, index, &value, getter, setter, attrs);
}
inline JSBool
JSObject::defineSpecial(JSContext *cx, js::SpecialId sid, const js::Value &value,
JSPropertyOp getter /* = JS_PropertyStub */,
JSStrictPropertyOp setter /* = JS_StrictPropertyStub */,
uintN attrs /* = JSPROP_ENUMERATE */)
{
return defineGeneric(cx, SPECIALID_TO_JSID(sid), value, getter, setter, attrs);
}
inline JSBool
JSObject::lookupElement(JSContext *cx, uint32 index, JSObject **objp, JSProperty **propp)
{

View File

@ -820,8 +820,8 @@ Walk(JSContext *cx, JSObject *holder, jsid name, const Value &reviver, Value *vp
JS_ALWAYS_TRUE(array_deleteElement(cx, obj, i, &newElement, false));
} else {
/* Step 2a(iii)(3). */
JS_ALWAYS_TRUE(array_defineProperty(cx, obj, id, &newElement, JS_PropertyStub,
JS_StrictPropertyStub, JSPROP_ENUMERATE));
JS_ALWAYS_TRUE(array_defineElement(cx, obj, i, &newElement, JS_PropertyStub,
JS_StrictPropertyStub, JSPROP_ENUMERATE));
}
}
} else {
@ -884,11 +884,8 @@ Revive(JSContext *cx, const Value &reviver, Value *vp)
if (!obj)
return false;
AutoObjectRooter tvr(cx, obj);
if (!obj->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.emptyAtom),
*vp, NULL, NULL, JSPROP_ENUMERATE)) {
if (!obj->defineProperty(cx, cx->runtime->atomState.emptyAtom, *vp))
return false;
}
return Walk(cx, obj, ATOM_TO_JSID(cx->runtime->atomState.emptyAtom), reviver, vp);
}

View File

@ -955,8 +955,8 @@ proxy_LookupSpecial(JSContext *cx, JSObject *obj, SpecialId sid, JSObject **objp
}
static JSBool
proxy_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
proxy_DefineGeneric(JSContext *cx, JSObject *obj, jsid id, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
id = js_CheckForStringIndex(id);
@ -970,6 +970,13 @@ proxy_DefineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *value,
return Proxy::defineProperty(cx, obj, id, &desc);
}
static JSBool
proxy_DefineProperty(JSContext *cx, JSObject *obj, PropertyName *name, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return proxy_DefineGeneric(cx, obj, ATOM_TO_JSID(name), value, getter, setter, attrs);
}
static JSBool
proxy_DefineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
@ -977,14 +984,14 @@ proxy_DefineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *val
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return proxy_DefineProperty(cx, obj, id, value, getter, setter, attrs);
return proxy_DefineGeneric(cx, obj, id, value, getter, setter, attrs);
}
static JSBool
proxy_DefineSpecial(JSContext *cx, JSObject *obj, SpecialId sid, const Value *value,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return proxy_DefineProperty(cx, obj, SPECIALID_TO_JSID(sid), value, getter, setter, attrs);
return proxy_DefineGeneric(cx, obj, SPECIALID_TO_JSID(sid), value, getter, setter, attrs);
}
static JSBool
@ -1231,7 +1238,7 @@ JS_FRIEND_DATA(Class) js::ObjectProxyClass = {
proxy_LookupProperty,
proxy_LookupElement,
proxy_LookupSpecial,
proxy_DefineProperty,
proxy_DefineGeneric,
proxy_DefineProperty,
proxy_DefineElement,
proxy_DefineSpecial,
@ -1292,7 +1299,7 @@ JS_FRIEND_DATA(Class) js::OuterWindowProxyClass = {
proxy_LookupProperty,
proxy_LookupElement,
proxy_LookupSpecial,
proxy_DefineProperty,
proxy_DefineGeneric,
proxy_DefineProperty,
proxy_DefineElement,
proxy_DefineSpecial,
@ -1365,7 +1372,7 @@ JS_FRIEND_DATA(Class) js::FunctionProxyClass = {
proxy_LookupProperty,
proxy_LookupElement,
proxy_LookupSpecial,
proxy_DefineProperty,
proxy_DefineGeneric,
proxy_DefineProperty,
proxy_DefineElement,
proxy_DefineSpecial,

View File

@ -428,7 +428,7 @@ class NodeBuilder
if (!atom)
return false;
return obj->defineProperty(cx, ATOM_TO_JSID(atom), val);
return obj->defineProperty(cx, atom->asPropertyName(), val);
}
bool newNodeLoc(TokenPos *pos, Value *dst);

View File

@ -1524,10 +1524,8 @@ BuildFlatMatchArray(JSContext *cx, JSString *textstr, const FlatMatch &fm, Value
vp->setObject(*obj);
return obj->defineElement(cx, 0, StringValue(fm.pattern())) &&
obj->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.indexAtom),
Int32Value(fm.match())) &&
obj->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.inputAtom),
StringValue(textstr));
obj->defineProperty(cx, cx->runtime->atomState.indexAtom, Int32Value(fm.match())) &&
obj->defineProperty(cx, cx->runtime->atomState.inputAtom, StringValue(textstr));
}
typedef JSObject **MatchArgType;

View File

@ -12872,7 +12872,7 @@ InitPropertyByName(JSContext* cx, JSObject* obj, JSString** namep, ValueArgType
jsid id;
if (!RootedStringToId(cx, namep, &id) ||
!obj->defineProperty(cx, id, ValueArgToConstRef(arg), NULL, NULL, JSPROP_ENUMERATE)) {
!obj->defineGeneric(cx, id, ValueArgToConstRef(arg), NULL, NULL, JSPROP_ENUMERATE)) {
SetBuiltinError(tm);
return JS_FALSE;
}
@ -12931,7 +12931,7 @@ InitPropertyByIndex(JSContext* cx, JSObject* obj, int32 index, ValueArgType arg)
AutoIdRooter idr(cx);
if (!js_Int32ToId(cx, index, idr.addr()) ||
!obj->defineProperty(cx, idr.id(), ValueArgToConstRef(arg), NULL, NULL, JSPROP_ENUMERATE)) {
!obj->defineGeneric(cx, idr.id(), ValueArgToConstRef(arg), NULL, NULL, JSPROP_ENUMERATE)) {
SetBuiltinError(tm);
return JS_FALSE;
}

View File

@ -325,8 +325,8 @@ ArrayBuffer::obj_lookupSpecial(JSContext *cx, JSObject *obj, SpecialId sid,
}
JSBool
ArrayBuffer::obj_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
ArrayBuffer::obj_defineGeneric(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
if (JSID_IS_ATOM(id, cx->runtime->atomState.byteLengthAtom))
return true;
@ -337,6 +337,13 @@ ArrayBuffer::obj_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Val
return js_DefineProperty(cx, delegate, id, v, getter, setter, attrs);
}
JSBool
ArrayBuffer::obj_defineProperty(JSContext *cx, JSObject *obj, PropertyName *name, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return obj_defineGeneric(cx, obj, ATOM_TO_JSID(name), v, getter, setter, attrs);
}
JSBool
ArrayBuffer::obj_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
@ -351,7 +358,7 @@ JSBool
ArrayBuffer::obj_defineSpecial(JSContext *cx, JSObject *obj, SpecialId sid, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return obj_defineProperty(cx, obj, SPECIALID_TO_JSID(sid), v, getter, setter, attrs);
return obj_defineGeneric(cx, obj, SPECIALID_TO_JSID(sid), v, getter, setter, attrs);
}
JSBool
@ -1172,8 +1179,8 @@ class TypedArrayTemplate
}
static JSBool
obj_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
obj_defineGeneric(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
if (JSID_IS_ATOM(id, cx->runtime->atomState.lengthAtom))
return true;
@ -1182,6 +1189,13 @@ class TypedArrayTemplate
return obj_setProperty(cx, obj, id, &tmp, false);
}
static JSBool
obj_defineProperty(JSContext *cx, JSObject *obj, PropertyName *name, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return obj_defineGeneric(cx, obj, ATOM_TO_JSID(name), v, getter, setter, attrs);
}
static JSBool
obj_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
@ -1194,7 +1208,7 @@ class TypedArrayTemplate
obj_defineSpecial(JSContext *cx, JSObject *obj, SpecialId sid, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return obj_defineProperty(cx, obj, SPECIALID_TO_JSID(sid), v, getter, setter, attrs);
return obj_defineGeneric(cx, obj, SPECIALID_TO_JSID(sid), v, getter, setter, attrs);
}
static JSBool
@ -2072,7 +2086,7 @@ Class js::ArrayBufferClass = {
ArrayBuffer::obj_lookupProperty,
ArrayBuffer::obj_lookupElement,
ArrayBuffer::obj_lookupSpecial,
ArrayBuffer::obj_defineProperty,
ArrayBuffer::obj_defineGeneric,
ArrayBuffer::obj_defineProperty,
ArrayBuffer::obj_defineElement,
ArrayBuffer::obj_defineSpecial,
@ -2184,7 +2198,7 @@ JSFunctionSpec _typedArray::jsfuncs[] = { \
_typedArray::obj_lookupProperty, \
_typedArray::obj_lookupElement, \
_typedArray::obj_lookupSpecial, \
_typedArray::obj_defineProperty, \
_typedArray::obj_defineGeneric, \
_typedArray::obj_defineProperty, \
_typedArray::obj_defineElement, \
_typedArray::obj_defineSpecial, \
@ -2232,11 +2246,11 @@ InitTypedArrayClass(JSContext *cx, GlobalObject *global)
if (!LinkConstructorAndPrototype(cx, ctor, proto))
return NULL;
if (!ctor->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.BYTES_PER_ELEMENTAtom),
if (!ctor->defineProperty(cx, cx->runtime->atomState.BYTES_PER_ELEMENTAtom,
Int32Value(ArrayType::BYTES_PER_ELEMENT),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT | JSPROP_READONLY) ||
!proto->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.BYTES_PER_ELEMENTAtom),
!proto->defineProperty(cx, cx->runtime->atomState.BYTES_PER_ELEMENTAtom,
Int32Value(ArrayType::BYTES_PER_ELEMENT),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT | JSPROP_READONLY))

View File

@ -88,13 +88,14 @@ struct JS_FRIEND_API(ArrayBuffer) {
JSProperty **propp);
static JSBool
obj_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v,
obj_defineGeneric(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
static JSBool
obj_defineProperty(JSContext *cx, JSObject *obj, PropertyName *name, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
static JSBool
obj_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);
static JSBool
obj_defineSpecial(JSContext *cx, JSObject *obj, SpecialId sid, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs);

View File

@ -4787,8 +4787,8 @@ xml_lookupSpecial(JSContext *cx, JSObject *obj, SpecialId sid, JSObject **objp,
}
static JSBool
xml_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
xml_defineGeneric(JSContext *cx, JSObject *obj, jsid id, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
if (IsFunctionObject(*v) || getter || setter ||
(attrs & JSPROP_ENUMERATE) == 0 ||
@ -4800,6 +4800,13 @@ xml_defineProperty(JSContext *cx, JSObject *obj, jsid id, const Value *v,
return PutProperty(cx, obj, id, false, &tmp);
}
static JSBool
xml_defineProperty(JSContext *cx, JSObject *obj, PropertyName *name, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return xml_defineGeneric(cx, obj, ATOM_TO_JSID(name), v, getter, setter, attrs);
}
static JSBool
xml_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
@ -4807,14 +4814,14 @@ xml_defineElement(JSContext *cx, JSObject *obj, uint32 index, const Value *v,
jsid id;
if (!IndexToId(cx, index, &id))
return false;
return xml_defineProperty(cx, obj, id, v, getter, setter, attrs);
return xml_defineGeneric(cx, obj, id, v, getter, setter, attrs);
}
static JSBool
xml_defineSpecial(JSContext *cx, JSObject *obj, SpecialId sid, const Value *v,
PropertyOp getter, StrictPropertyOp setter, uintN attrs)
{
return xml_defineProperty(cx, obj, SPECIALID_TO_JSID(sid), v, getter, setter, attrs);
return xml_defineGeneric(cx, obj, SPECIALID_TO_JSID(sid), v, getter, setter, attrs);
}
static JSBool
@ -5330,7 +5337,7 @@ JS_FRIEND_DATA(Class) js::XMLClass = {
xml_lookupProperty,
xml_lookupElement,
xml_lookupSpecial,
xml_defineProperty,
xml_defineGeneric,
xml_defineProperty,
xml_defineElement,
xml_defineSpecial,
@ -7421,7 +7428,7 @@ js_InitXMLClass(JSContext *cx, JSObject *obj)
JS_DefineFunction(cx, global, js_XMLList_str, XMLList, 1, JSFUN_CONSTRUCTOR);
if (!xmllist)
return NULL;
if (!xmllist->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.classPrototypeAtom),
if (!xmllist->defineProperty(cx, cx->runtime->atomState.classPrototypeAtom,
ObjectValue(*xmlProto), JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT | JSPROP_READONLY))
{
@ -7523,8 +7530,8 @@ js_GetDefaultXMLNamespace(JSContext *cx, jsval *vp)
if (!ns)
return JS_FALSE;
v = OBJECT_TO_JSVAL(ns);
if (!obj->defineProperty(cx, JS_DEFAULT_XML_NAMESPACE_ID, v,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT)) {
if (!obj->defineSpecial(cx, SpecialId::defaultXMLNamespace(), v,
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT)) {
return JS_FALSE;
}
*vp = v;
@ -7542,8 +7549,8 @@ js_SetDefaultXMLNamespace(JSContext *cx, const Value &v)
return JS_FALSE;
JSObject &varobj = cx->fp()->varObj();
if (!varobj.defineProperty(cx, JS_DEFAULT_XML_NAMESPACE_ID, ObjectValue(*ns),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT)) {
if (!varobj.defineSpecial(cx, SpecialId::defaultXMLNamespace(), ObjectValue(*ns),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT)) {
return JS_FALSE;
}
return JS_TRUE;

View File

@ -796,10 +796,15 @@ stubs::DefFun(VMFrame &f, JSFunction *fun)
Value rval = ObjectValue(*obj);
do {
PropertyName *name = fun->atom->asPropertyName();
/* Steps 5d, 5f. */
if (!prop || pobj != parent) {
if (!parent->defineProperty(cx, id, rval, JS_PropertyStub, JS_StrictPropertyStub, attrs))
if (!parent->defineProperty(cx, name, rval,
JS_PropertyStub, JS_StrictPropertyStub, attrs))
{
THROW();
}
break;
}
@ -808,8 +813,11 @@ stubs::DefFun(VMFrame &f, JSFunction *fun)
Shape *shape = reinterpret_cast<Shape *>(prop);
if (parent->isGlobal()) {
if (shape->configurable()) {
if (!parent->defineProperty(cx, id, rval, JS_PropertyStub, JS_StrictPropertyStub, attrs))
if (!parent->defineProperty(cx, name, rval,
JS_PropertyStub, JS_StrictPropertyStub, attrs))
{
THROW();
}
break;
}
@ -1370,7 +1378,7 @@ stubs::InitElem(VMFrame &f, uint32 last)
if (last && !js_SetLengthProperty(cx, obj, (jsuint) (JSID_TO_INT(id) + 1)))
THROW();
} else {
if (!obj->defineProperty(cx, id, rref, NULL, NULL, JSPROP_ENUMERATE))
if (!obj->defineGeneric(cx, id, rref, NULL, NULL, JSPROP_ENUMERATE))
THROW();
}
}
@ -2308,7 +2316,7 @@ stubs::SetConst(VMFrame &f, JSAtom *atom)
JSObject *obj = &f.fp()->varObj();
const Value &ref = f.regs.sp[-1];
if (!obj->defineProperty(cx, ATOM_TO_JSID(atom), ref,
if (!obj->defineProperty(cx, atom->asPropertyName(), ref,
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY)) {
THROW();

View File

@ -2186,7 +2186,7 @@ DebuggerScript_getAllOffsets(JSContext *cx, uintN argc, Value *vp)
offsets = NewDenseEmptyArray(cx);
if (!offsets ||
!ValueToId(cx, NumberValue(lineno), &id) ||
!result->defineProperty(cx, id, ObjectValue(*offsets)))
!result->defineGeneric(cx, id, ObjectValue(*offsets)))
{
return false;
}

View File

@ -282,7 +282,7 @@ GlobalObject::initStandardClasses(JSContext *cx)
JSAtomState &state = cx->runtime->atomState;
/* Define a top-level property 'undefined' with the undefined value. */
if (!defineProperty(cx, ATOM_TO_JSID(state.typeAtoms[JSTYPE_VOID]), UndefinedValue(),
if (!defineProperty(cx, state.typeAtoms[JSTYPE_VOID], UndefinedValue(),
JS_PropertyStub, JS_StrictPropertyStub, JSPROP_PERMANENT | JSPROP_READONLY))
{
return false;
@ -416,10 +416,10 @@ GlobalObject::createBlankPrototypeInheriting(JSContext *cx, Class *clasp, JSObje
bool
LinkConstructorAndPrototype(JSContext *cx, JSObject *ctor, JSObject *proto)
{
return ctor->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.classPrototypeAtom),
return ctor->defineProperty(cx, cx->runtime->atomState.classPrototypeAtom,
ObjectValue(*proto), JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_PERMANENT | JSPROP_READONLY) &&
proto->defineProperty(cx, ATOM_TO_JSID(cx->runtime->atomState.constructorAtom),
proto->defineProperty(cx, cx->runtime->atomState.constructorAtom,
ObjectValue(*ctor), JS_PropertyStub, JS_StrictPropertyStub, 0);
}