зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1265594 - Expose FromPropertyDescriptor() as a public JS API; r=jorendorff
This commit is contained in:
Родитель
fd41a201a0
Коммит
8560e8e9d4
|
@ -677,7 +677,7 @@ js::obj_getOwnPropertyDescriptor(JSContext* cx, unsigned argc, Value* vp)
|
|||
// Steps 5-7.
|
||||
Rooted<PropertyDescriptor> desc(cx);
|
||||
return GetOwnPropertyDescriptor(cx, obj, id, &desc) &&
|
||||
FromPropertyDescriptor(cx, desc, args.rval());
|
||||
JS::FromPropertyDescriptor(cx, desc, args.rval());
|
||||
}
|
||||
|
||||
enum EnumerableOwnPropertiesKind {
|
||||
|
|
|
@ -17,6 +17,24 @@ BEGIN_TEST(test_GetPropertyDescriptor)
|
|||
CHECK_EQUAL(desc.object(), obj);
|
||||
CHECK_SAME(desc.value(), JS::Int32Value(123));
|
||||
|
||||
JS::RootedValue descValue(cx);
|
||||
CHECK(JS::FromPropertyDescriptor(cx, desc, &descValue));
|
||||
CHECK(descValue.isObject());
|
||||
JS::RootedObject descObj(cx, &descValue.toObject());
|
||||
JS::RootedValue value(cx);
|
||||
CHECK(JS_GetProperty(cx, descObj, "value", &value));
|
||||
CHECK_EQUAL(value.toInt32(), 123);
|
||||
CHECK(JS_GetProperty(cx, descObj, "get", &value));
|
||||
CHECK(value.isUndefined());
|
||||
CHECK(JS_GetProperty(cx, descObj, "set", &value));
|
||||
CHECK(value.isUndefined());
|
||||
CHECK(JS_GetProperty(cx, descObj, "writable", &value));
|
||||
CHECK(value.isTrue());
|
||||
CHECK(JS_GetProperty(cx, descObj, "configurable", &value));
|
||||
CHECK(value.isTrue());
|
||||
CHECK(JS_GetProperty(cx, descObj, "enumerable", &value));
|
||||
CHECK(value.isTrue());
|
||||
|
||||
CHECK(JS_GetPropertyDescriptor(cx, obj, "not-here", &desc));
|
||||
CHECK_EQUAL(desc.object(), nullptr);
|
||||
|
||||
|
|
|
@ -2846,6 +2846,16 @@ ObjectToCompletePropertyDescriptor(JSContext* cx,
|
|||
JS::HandleValue descriptor,
|
||||
JS::MutableHandle<PropertyDescriptor> desc);
|
||||
|
||||
/*
|
||||
* ES6 draft rev 32 (2015 Feb 2) 6.2.4.4 FromPropertyDescriptor(Desc).
|
||||
*
|
||||
* If desc.object() is null, then vp is set to undefined.
|
||||
*/
|
||||
extern JS_PUBLIC_API(bool)
|
||||
FromPropertyDescriptor(JSContext* cx,
|
||||
JS::Handle<JS::PropertyDescriptor> desc,
|
||||
JS::MutableHandleValue vp);
|
||||
|
||||
} // namespace JS
|
||||
|
||||
|
||||
|
|
|
@ -108,9 +108,13 @@ js::InformalValueTypeName(const Value& v)
|
|||
}
|
||||
|
||||
// ES6 draft rev37 6.2.4.4 FromPropertyDescriptor
|
||||
bool
|
||||
js::FromPropertyDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp)
|
||||
JS_PUBLIC_API(bool)
|
||||
JS::FromPropertyDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp)
|
||||
{
|
||||
AssertHeapIsIdle(cx);
|
||||
CHECK_REQUEST(cx);
|
||||
assertSameCompartment(cx, desc);
|
||||
|
||||
// Step 1.
|
||||
if (!desc.object()) {
|
||||
vp.setUndefined();
|
||||
|
|
|
@ -1241,18 +1241,10 @@ bool
|
|||
GetOwnPropertyDescriptor(JSContext* cx, HandleObject obj, HandleId id, MutableHandleValue vp);
|
||||
|
||||
/*
|
||||
* ES6 draft rev 32 (2015 Feb 2) 6.2.4.4 FromPropertyDescriptor(Desc).
|
||||
*
|
||||
* If desc.object() is null, then vp is set to undefined.
|
||||
*/
|
||||
extern bool
|
||||
FromPropertyDescriptor(JSContext* cx, Handle<PropertyDescriptor> desc, MutableHandleValue vp);
|
||||
|
||||
/*
|
||||
* Like FromPropertyDescriptor, but ignore desc.object() and always set vp
|
||||
* Like JS::FromPropertyDescriptor, but ignore desc.object() and always set vp
|
||||
* to an object on success.
|
||||
*
|
||||
* Use FromPropertyDescriptor for getOwnPropertyDescriptor, since desc.object()
|
||||
* Use JS::FromPropertyDescriptor for getOwnPropertyDescriptor, since desc.object()
|
||||
* is used to indicate whether a result was found or not. Use this instead for
|
||||
* defineProperty: it would be senseless to define a "missing" property.
|
||||
*/
|
||||
|
|
|
@ -8188,7 +8188,7 @@ DebuggerObject_getOwnPropertyDescriptor(JSContext* cx, unsigned argc, Value* vp)
|
|||
}
|
||||
}
|
||||
|
||||
return FromPropertyDescriptor(cx, desc, args.rval());
|
||||
return JS::FromPropertyDescriptor(cx, desc, args.rval());
|
||||
}
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче