Bug 1125356 - Introduce JS_NewPlainObject. r=Waldo

This commit is contained in:
Tom Schuster 2015-01-24 16:38:08 +01:00
parent 18683688f4
commit a29cc5e499
27 changed files with 51 additions and 38 deletions

View File

@ -511,7 +511,7 @@ js::ExecuteInGlobalAndReturnScope(JSContext *cx, HandleObject global, HandleScri
Debugger::onNewScript(cx, script, global);
}
RootedObject scope(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
RootedObject scope(cx, JS_NewPlainObject(cx));
if (!scope)
return false;

View File

@ -51,7 +51,7 @@ static bool
GetBuildConfiguration(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject info(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
RootedObject info(cx, JS_NewPlainObject(cx));
if (!info)
return false;
@ -1425,7 +1425,7 @@ static bool
GetJitCompilerOptions(JSContext *cx, unsigned argc, jsval *vp)
{
CallArgs args = CallArgsFromVp(argc, vp);
RootedObject info(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
RootedObject info(cx, JS_NewPlainObject(cx));
if (!info)
return false;

View File

@ -935,7 +935,7 @@ InitCTypeClass(JSContext* cx, HandleObject parent)
static JSObject*
InitABIClass(JSContext* cx, JSObject* parent)
{
RootedObject obj(cx, JS_NewObject(cx, nullptr, NullPtr(), NullPtr()));
RootedObject obj(cx, JS_NewPlainObject(cx));
if (!obj)
return nullptr;
@ -4773,7 +4773,7 @@ AddFieldToArray(JSContext* cx,
{
RootedObject typeObj(cx, typeObj_);
Rooted<JSFlatString*> name(cx, name_);
RootedObject fieldObj(cx, JS_NewObject(cx, nullptr, NullPtr(), NullPtr()));
RootedObject fieldObj(cx, JS_NewPlainObject(cx));
if (!fieldObj)
return false;

View File

@ -3,7 +3,7 @@
FRAGMENT(JSObject, simple) {
JS::Rooted<JSObject *> glob(cx, JS::CurrentGlobalOrNull(cx));
JS::Rooted<JSObject *> plain(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::Rooted<JSObject *> plain(cx, JS_NewPlainObject(cx));
JS::Rooted<JSObject *> global(cx, JS::CurrentGlobalOrNull(cx));
JS::Rooted<JSObject *> func(cx, (JSObject *) JS_NewFunction(cx, (JSNative) 1, 0, 0,
global, "dys"));

View File

@ -38,7 +38,7 @@ FRAGMENT(Root, HeapSlot) {
}
FRAGMENT(Root, barriers) {
JSObject *obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
JSObject *obj = JS_NewPlainObject(cx);
js::PreBarriered<JSObject *> prebarriered(obj);
js::HeapPtr<JSObject *> heapptr(obj);
js::RelocatablePtr<JSObject *> relocatable(obj);

View File

@ -30,7 +30,7 @@ BEGIN_TEST(testAddPropertyHook)
*/
static const int ExpectedCount = 100;
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj);
JS::RootedValue proto(cx, OBJECT_TO_JSVAL(obj));
JS_InitClass(cx, global, obj, &AddPropertyClass, nullptr, 0, nullptr, nullptr, nullptr,

View File

@ -18,7 +18,7 @@ BEGIN_TEST(testDefineGetterSetterNonEnumerable)
static const char PROPERTY_NAME[] = "foo";
JS::RootedValue vobj(cx);
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj);
vobj = OBJECT_TO_JSVAL(obj);

View File

@ -41,7 +41,7 @@ CheckDescriptor(JS::Handle<JSPropertyDescriptor> desc, bool enumerable,
BEGIN_TEST(testDefinePropertyIgnoredAttributes)
{
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
JS::Rooted<JSPropertyDescriptor> desc(cx);
JS::RootedValue defineValue(cx);

View File

@ -45,8 +45,7 @@ END_TEST(testForOfIterator_bug515273_part1)
BEGIN_TEST(testForOfIterator_bug515273_part2)
{
JS::RootedObject obj(cx,
JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj);
JS::RootedValue v(cx, JS::ObjectValue(*obj));

View File

@ -20,7 +20,7 @@ GivesAndTakesCells(JS::GCCellPtr cell)
BEGIN_TEST(testGCCellPtr)
{
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj);
JS::RootedString str(cx, JS_NewStringCopyZ(cx, "probably foobar"));

View File

@ -9,8 +9,8 @@
BEGIN_TEST(testGCExactRooting)
{
JS::RootedObject rootCx(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject rootRt(cx->runtime(), JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject rootCx(cx, JS_NewPlainObject(cx));
JS::RootedObject rootRt(cx->runtime(), JS_NewPlainObject(cx));
JS_GC(cx->runtime());

View File

@ -70,7 +70,7 @@ TestHeapPostBarriers(T initialObj)
JSObject *NurseryObject()
{
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
if (!obj)
return nullptr;
JS_DefineProperty(cx, obj, "x", 42, 0);

View File

@ -53,7 +53,7 @@ BEGIN_TEST(testTracingIncomingCCWs)
// Define an object in one zone, that is wrapped by a CCW in another zone.
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj->zone() == global1->zone());
JSAutoCompartment ac(cx, global2);

View File

@ -70,9 +70,9 @@ BEGIN_TEST(testGCNurseryFinalizer)
CHECK(ranFinalizer == 0);
// Null finalization list with non-empty nursery.
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewPlainObject(cx);
obj = JS_NewPlainObject(cx);
obj = JS_NewPlainObject(cx);
CHECK(js::gc::IsInsideNursery(obj));
obj = nullptr;
rt->gc.minorGC(JS::gcreason::EVICT_NURSERY);
@ -97,15 +97,15 @@ BEGIN_TEST(testGCNurseryFinalizer)
ranFinalizer = 0;
// Interleaved finalizable things in nursery.
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewPlainObject(cx);
obj = JS_NewObject(cx, Jsvalify(&NurseryClass), JS::NullPtr(), JS::NullPtr());
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewPlainObject(cx);
obj = JS_NewObject(cx, Jsvalify(&NurseryClass), JS::NullPtr(), JS::NullPtr());
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewPlainObject(cx);
obj = JS_NewObject(cx, Jsvalify(&NurseryClass), JS::NullPtr(), JS::NullPtr());
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewPlainObject(cx);
obj = JS_NewObject(cx, Jsvalify(&NurseryClass), JS::NullPtr(), JS::NullPtr());
obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
obj = JS_NewPlainObject(cx);
CHECK(js::gc::IsInsideNursery(obj));
obj = nullptr;
rt->gc.minorGC(JS::gcreason::EVICT_NURSERY);

View File

@ -116,6 +116,6 @@ BEGIN_TEST(testGCStoreBufferRemoval)
JSObject *NurseryObject()
{
return JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
return JS_NewPlainObject(cx);
}
END_TEST(testGCStoreBufferRemoval)

View File

@ -15,7 +15,7 @@ BEGIN_TEST(testIsInsideNursery)
JS_GC(rt);
JS::RootedObject object(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject object(cx, JS_NewPlainObject(cx));
/* Objects are initially allocated in the nursery. */
CHECK(js::gc::IsInsideNursery(object));

View File

@ -6,7 +6,7 @@
BEGIN_TEST(testJSEvaluateScript)
{
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), global));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj);
CHECK(JS::RuntimeOptionsRef(cx).varObjFix());

View File

@ -14,7 +14,7 @@ constructHook(JSContext *cx, unsigned argc, jsval *vp)
// Check that arguments were passed properly from JS_New.
JS::RootedObject obj(cx, JS_NewObject(cx, js::Jsvalify(&js::PlainObject::class_), JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
if (!obj) {
JS_ReportError(cx, "test failed, could not construct object");
return false;

View File

@ -9,7 +9,7 @@
BEGIN_TEST(testSetProperty_NativeGetterStubSetter)
{
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
CHECK(obj);
CHECK(JS_DefineProperty(cx, global, "globalProp", obj, JSPROP_ENUMERATE,

View File

@ -19,7 +19,7 @@ BEGIN_TEST(testStructuredClone_object)
JSAutoCompartment ac(cx, g1);
JS::RootedValue prop(cx, JS::Int32Value(1337));
JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
JS::RootedObject obj(cx, JS_NewPlainObject(cx));
v1 = JS::ObjectOrNullValue(obj);
CHECK(v1.isObject());
CHECK(JS_SetProperty(cx, obj, "prop", prop));

View File

@ -49,7 +49,7 @@ BEGIN_TEST(testWeakMap_basicOperations)
JSObject *newKey()
{
return JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
return JS_NewPlainObject(cx);
}
bool
@ -185,7 +185,7 @@ JSObject *newCCW(JS::HandleObject sourceZone, JS::HandleObject destZone)
JS::RootedObject object(cx);
{
JSAutoCompartment ac(cx, destZone);
object = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
object = JS_NewPlainObject(cx);
if (!object)
return nullptr;
}

View File

@ -2084,6 +2084,16 @@ JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *jsclasp, HandleObject p
return obj;
}
JS_PUBLIC_API(JSObject *)
JS_NewPlainObject(JSContext *cx)
{
MOZ_ASSERT(!cx->runtime()->isAtomsCompartment(cx->compartment()));
AssertHeapIsIdle(cx);
CHECK_REQUEST(cx);
return NewBuiltinClassInstance<PlainObject>(cx);
}
JS_PUBLIC_API(JSObject *)
JS_NewObjectForConstructor(JSContext *cx, const JSClass *clasp, const CallArgs& args)
{

View File

@ -2793,6 +2793,10 @@ extern JS_PUBLIC_API(JSObject *)
JS_NewObjectWithGivenProto(JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto,
JS::Handle<JSObject*> parent);
// Creates a new plain object, like `new Object()`, with Object.prototype as [[Prototype]].
extern JS_PUBLIC_API(JSObject *)
JS_NewPlainObject(JSContext *cx);
/*
* Freeze obj, and all objects it refers to, recursively. This will not recurse
* through non-extensible objects, on the assumption that those are already

View File

@ -1052,7 +1052,7 @@ JS::ObjectPtr::trace(JSTracer *trc, const char *name)
JS_FRIEND_API(JSObject *)
js::GetTestingFunctions(JSContext *cx)
{
RootedObject obj(cx, JS_NewObject(cx, nullptr, NullPtr(), NullPtr()));
RootedObject obj(cx, JS_NewPlainObject(cx));
if (!obj)
return nullptr;

View File

@ -236,7 +236,7 @@ os_waitpid(JSContext* cx, unsigned argc, Value* vp)
return false;
}
RootedObject info(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
RootedObject info(cx, JS_NewPlainObject(cx));
if (!info)
return false;
@ -293,7 +293,7 @@ static const JSFunctionSpecWithHelp os_functions[] = {
bool
js::DefineOS(JSContext *cx, HandleObject global)
{
RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
RootedObject obj(cx, JS_NewPlainObject(cx));
return obj &&
JS_DefineFunctionsWithHelp(cx, obj, os_functions) &&
JS_DefineProperty(cx, global, "os", obj, 0);

View File

@ -4708,7 +4708,7 @@ static const JSFunctionSpecWithHelp console_functions[] = {
bool
DefineConsole(JSContext *cx, HandleObject global)
{
RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
RootedObject obj(cx, JS_NewPlainObject(cx));
return obj &&
JS_DefineFunctionsWithHelp(cx, obj, console_functions) &&
JS_DefineProperty(cx, global, "console", obj, 0);

View File

@ -531,7 +531,7 @@ ReferenceFinder::addReferrer(jsval referrerArg, Path *path)
JSObject *
ReferenceFinder::findReferences(HandleObject target)
{
result = JS_NewObject(context, nullptr, JS::NullPtr(), JS::NullPtr());
result = JS_NewPlainObject(context);
if (!result)
return nullptr;
if (!visit(target, nullptr))