Bug 1506324 - Use DefaultGlobalClassOps in existing code. r=jorendorff

Summary: Depends on D11570

Reviewers: tcampbell, jorendorff

Reviewed By: tcampbell, jorendorff

Subscribers: jandem

Bug #: 1506324

Differential Revision: https://phabricator.services.mozilla.com/D11571
This commit is contained in:
Philip Chimento 2018-11-19 09:05:07 -05:00
Родитель 051426775c
Коммит 31c3522845
12 изменённых файлов: 41 добавлений и 121 удалений

Просмотреть файл

@ -69,15 +69,9 @@ struct DevTools : public ::testing::Test {
} }
static const JSClass* getGlobalClass() { static const JSClass* getGlobalClass() {
static const JSClassOps globalClassOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
JS_GlobalObjectTraceHook
};
static const JSClass globalClass = { static const JSClass globalClass = {
"global", JSCLASS_GLOBAL_FLAGS, "global", JSCLASS_GLOBAL_FLAGS,
&globalClassOps &JS::DefaultGlobalClassOps
}; };
return &globalClass; return &globalClass;
} }
@ -85,21 +79,9 @@ struct DevTools : public ::testing::Test {
JSObject* createGlobal() JSObject* createGlobal()
{ {
/* Create the global object. */ /* Create the global object. */
JS::RootedObject newGlobal(cx);
JS::RealmOptions options; JS::RealmOptions options;
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), nullptr, return JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
JS::FireOnNewGlobalHook, options); JS::FireOnNewGlobalHook, options);
if (!newGlobal)
return nullptr;
JSAutoRealm ar(cx, newGlobal);
/* Populate the global object with the standard globals, like Object and
Array. */
if (!JS::InitRealmStandardClasses(cx))
return nullptr;
return newGlobal;
} }
virtual void TearDown() { virtual void TearDown() {

Просмотреть файл

@ -25,15 +25,9 @@ JSContext* gCx = nullptr;
static const JSClass* static const JSClass*
getGlobalClass() getGlobalClass()
{ {
static const JSClassOps cOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
JS_GlobalObjectTraceHook
};
static const JSClass c = { static const JSClass c = {
"global", JSCLASS_GLOBAL_FLAGS, "global", JSCLASS_GLOBAL_FLAGS,
&cOps &JS::DefaultGlobalClassOps
}; };
return &c; return &c;
} }
@ -42,27 +36,13 @@ static JSObject*
jsfuzz_createGlobal(JSContext* cx, JSPrincipals* principals) jsfuzz_createGlobal(JSContext* cx, JSPrincipals* principals)
{ {
/* Create the global object. */ /* Create the global object. */
JS::RootedObject newGlobal(cx);
JS::RealmOptions options; JS::RealmOptions options;
options.creationOptions().setStreamsEnabled(true); options.creationOptions().setStreamsEnabled(true);
#ifdef ENABLE_BIGINT #ifdef ENABLE_BIGINT
options.creationOptions().setBigIntEnabled(true); options.creationOptions().setBigIntEnabled(true);
#endif #endif
newGlobal = JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook, return JS_NewGlobalObject(cx, getGlobalClass(), principals, JS::FireOnNewGlobalHook,
options); options);
if (!newGlobal) {
return nullptr;
}
JSAutoRealm ar(cx, newGlobal);
// Populate the global object with the standard globals like Object and
// Array.
if (!JS::InitRealmStandardClasses(cx)) {
return nullptr;
}
return newGlobal;
} }
static bool static bool

Просмотреть файл

@ -13,17 +13,10 @@
using namespace JS; using namespace JS;
static const JSClassOps global_classOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
JS_GlobalObjectTraceHook
};
/* The class of the global object. */ /* The class of the global object. */
static const JSClass global_class = { static const JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS, "global", JSCLASS_GLOBAL_FLAGS,
&global_classOps &DefaultGlobalClassOps
}; };
static volatile int dontOptimizeMeAway = 0; static volatile int dontOptimizeMeAway = 0;
@ -90,10 +83,6 @@ main(int argc, const char** argv)
nullptr, JS::FireOnNewGlobalHook, options))); nullptr, JS::FireOnNewGlobalHook, options)));
JSAutoRealm ar(cx, global); JSAutoRealm ar(cx, global);
/* Populate the global object with the standard globals,
like Object and Array. */
checkBool(JS::InitRealmStandardClasses(cx));
argv++; argv++;
while (*argv) { while (*argv) {
const char* name = *argv++; const char* name = *argv++;

Просмотреть файл

@ -9,24 +9,10 @@
static TestJSPrincipals system_principals(1); static TestJSPrincipals system_principals(1);
static const JSClassOps global_classOps = {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
JS_GlobalObjectTraceHook
};
static const JSClass global_class = { static const JSClass global_class = {
"global", "global",
JSCLASS_IS_GLOBAL | JSCLASS_GLOBAL_FLAGS, JSCLASS_IS_GLOBAL | JSCLASS_GLOBAL_FLAGS,
&global_classOps &JS::DefaultGlobalClassOps
}; };
static JS::PersistentRootedObject trusted_glob; static JS::PersistentRootedObject trusted_glob;

Просмотреть файл

@ -18,10 +18,6 @@ BEGIN_TEST(testDebugger_newScriptHook)
JS::RootedObject g(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr, JS::RootedObject g(cx, JS_NewGlobalObject(cx, getGlobalClass(), nullptr,
JS::FireOnNewGlobalHook, options)); JS::FireOnNewGlobalHook, options));
CHECK(g); CHECK(g);
{
JSAutoRealm ar(cx, g);
CHECK(JS::InitRealmStandardClasses(cx));
}
JS::RootedObject gWrapper(cx, g); JS::RootedObject gWrapper(cx, g);
CHECK(JS_WrapObject(cx, &gWrapper)); CHECK(JS_WrapObject(cx, &gWrapper));

Просмотреть файл

@ -50,8 +50,6 @@ eval(const char* asciiChars, bool mutedErrors, JS::MutableHandleValue rval)
JS::FireOnNewGlobalHook, globalOptions)); JS::FireOnNewGlobalHook, globalOptions));
CHECK(global); CHECK(global);
JSAutoRealm ar(cx, global); JSAutoRealm ar(cx, global);
CHECK(JS::InitRealmStandardClasses(cx));
JS::CompileOptions options(cx); JS::CompileOptions options(cx);
options.setMutedErrors(mutedErrors) options.setMutedErrors(mutedErrors)

Просмотреть файл

@ -9,11 +9,13 @@
BEGIN_TEST(testSetProperty_InheritedGlobalSetter) BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
{ {
// This is a JSAPI test because jsapi-test globals do not have a resolve // This is a JSAPI test because jsapi-test globals can be set up to not have
// hook and therefore can use the property cache in some cases where the // a resolve hook and therefore can use the property cache in some cases
// shell can't. // where the shell can't.
MOZ_RELEASE_ASSERT(!JS_GetClass(global)->getResolve()); MOZ_RELEASE_ASSERT(!JS_GetClass(global)->getResolve());
CHECK(JS::InitRealmStandardClasses(cx));
CHECK(JS_DefineProperty(cx, global, "HOTLOOP", 8, 0)); CHECK(JS_DefineProperty(cx, global, "HOTLOOP", 8, 0));
EXEC("var n = 0;\n" EXEC("var n = 0;\n"
"var global = this;\n" "var global = this;\n"
@ -25,4 +27,28 @@ BEGIN_TEST(testSetProperty_InheritedGlobalSetter)
" throw 'FAIL';\n"); " throw 'FAIL';\n");
return true; return true;
} }
const JSClass* getGlobalClass(void) override {
static const JSClassOps noResolveGlobalClassOps = {
nullptr, // add
nullptr, // delete
nullptr, // enumerate
nullptr, // newEnumerate
nullptr, // resolve
nullptr, // mayResolve
nullptr, // finalize
nullptr, // call
nullptr, // hasInstance
nullptr, // construct
JS_GlobalObjectTraceHook
};
static const JSClass noResolveGlobalClass = {
"testSetProperty_InheritedGlobalSetter_noResolveGlobalClass",
JSCLASS_GLOBAL_FLAGS,
&noResolveGlobalClassOps
};
return &noResolveGlobalClass;
}
END_TEST(testSetProperty_InheritedGlobalSetter) END_TEST(testSetProperty_InheritedGlobalSetter)

Просмотреть файл

@ -95,14 +95,6 @@ JSObject* JSAPITest::createGlobal(JSPrincipals* principals)
return nullptr; return nullptr;
} }
JSAutoRealm ar(cx, newGlobal);
// Populate the global object with the standard globals like Object and
// Array.
if (!JS::InitRealmStandardClasses(cx)) {
return nullptr;
}
global = newGlobal; global = newGlobal;
return newGlobal; return newGlobal;
} }

Просмотреть файл

@ -261,15 +261,9 @@ class JSAPITest
JSAPITestString messages() const { return msgs; } JSAPITestString messages() const { return msgs; }
static const JSClass * basicGlobalClass() { static const JSClass * basicGlobalClass() {
static const JSClassOps cOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
JS_GlobalObjectTraceHook
};
static const JSClass c = { static const JSClass c = {
"global", JSCLASS_GLOBAL_FLAGS, "global", JSCLASS_GLOBAL_FLAGS,
&cOps &JS::DefaultGlobalClassOps
}; };
return &c; return &c;
} }

Просмотреть файл

@ -429,16 +429,9 @@ js::HasOffThreadIonCompile(Realm* realm)
} }
#endif #endif
static const JSClassOps parseTaskGlobalClassOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
JS_GlobalObjectTraceHook
};
static const JSClass parseTaskGlobalClass = { static const JSClass parseTaskGlobalClass = {
"internal-parse-task-global", JSCLASS_GLOBAL_FLAGS, "internal-parse-task-global", JSCLASS_GLOBAL_FLAGS,
&parseTaskGlobalClassOps &JS::DefaultGlobalClassOps
}; };
ParseTask::ParseTask(ParseTaskKind kind, JSContext* cx, ParseTask::ParseTask(ParseTaskKind kind, JSContext* cx,

Просмотреть файл

@ -680,9 +680,6 @@ private:
JSAutoRealm ar(mContext, global); JSAutoRealm ar(mContext, global);
AutoPACErrorReporter aper(mContext); AutoPACErrorReporter aper(mContext);
if (!JS::InitRealmStandardClasses(mContext)) {
return NS_ERROR_FAILURE;
}
if (!JS_DefineFunctions(mContext, global, PACGlobalFunctions)) { if (!JS_DefineFunctions(mContext, global, PACGlobalFunctions)) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -693,17 +690,10 @@ private:
} }
}; };
static const JSClassOps sJSContextWrapperGlobalClassOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr,
JS_GlobalObjectTraceHook
};
const JSClass JSContextWrapper::sGlobalClass = { const JSClass JSContextWrapper::sGlobalClass = {
"PACResolutionThreadGlobal", "PACResolutionThreadGlobal",
JSCLASS_GLOBAL_FLAGS, JSCLASS_GLOBAL_FLAGS,
&sJSContextWrapperGlobalClassOps &JS::DefaultGlobalClassOps
}; };
void void

Просмотреть файл

@ -84,15 +84,9 @@ RunTest(JSContext* cx, ArrayT* array)
static void static void
CreateGlobalAndRunTest(JSContext* cx) CreateGlobalAndRunTest(JSContext* cx)
{ {
static const JSClassOps GlobalClassOps = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, JS_GlobalObjectTraceHook
};
static const JSClass GlobalClass = { static const JSClass GlobalClass = {
"global", JSCLASS_GLOBAL_FLAGS, "global", JSCLASS_GLOBAL_FLAGS,
&GlobalClassOps &JS::DefaultGlobalClassOps
}; };
JS::RealmOptions options; JS::RealmOptions options;