Bug 1506324 - Add JS::DefaultGlobalClassOps to JSAPI. r=ptomato
☠☠ backed out by 1eeecfde9fe1 ☠ ☠
authorPhilip Chimento <philip.chimento@gmail.com>
Mon, 12 Nov 2018 22:35:10 -0500
changeset 503545 412920e602faa64d31b4a07a8d9d068413f04bc0
parent 503544 f00f5277735f4f5a4784659716f7ceede6a339b6
child 503546 d21e9cf5a196cd23f56f56c4443b1272d94ccd58
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersptomato
bugs1506324
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506324 - Add JS::DefaultGlobalClassOps to JSAPI. r=ptomato Reviewers: jorendorff Subscribers: jandem Bug #: 1506324 Differential Revision: https://phabricator.services.mozilla.com/D11570
js/src/jsapi.cpp
js/src/jsapi.h
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -1934,16 +1934,30 @@ const JSClassOps JS::DefaultGlobalClassO
     JS_MayResolveStandardClass,
     nullptr,  // finalize
     nullptr,  // call
     nullptr,  // hasInstance
     nullptr,  // construct
     JS_GlobalObjectTraceHook
 };
 
+const JSClassOps JS::DefaultGlobalClassOps = {
+    nullptr,  // addProperty
+    nullptr,  // deleteProperty
+    nullptr,  // enumerate
+    JS_NewEnumerateStandardClasses,
+    JS_ResolveStandardClass,
+    JS_MayResolveStandardClass,
+    nullptr,  // finalize
+    nullptr,  // call
+    nullptr,  // hasInstance
+    nullptr,  // construct
+    JS_GlobalObjectTraceHook
+};
+
 JS_PUBLIC_API(void)
 JS_FireOnNewGlobalObject(JSContext* cx, JS::HandleObject global)
 {
     // This hook is infallible, because we don't really want arbitrary script
     // to be able to throw errors during delicate global creation routines.
     // This infallibility will eat OOM and slow script, but if that happens
     // we'll likely run up into them again soon in a fallible context.
     cx->check(global);
--- a/js/src/jsapi.h
+++ b/js/src/jsapi.h
@@ -1845,16 +1845,31 @@ namespace JS {
  *     const JSClass globalClass = { "MyGlobal", JSCLASS_GLOBAL_FLAGS,
  *         &JS::DefaultGlobalClassOps };
  *     JS_NewGlobalObject(cx, &globalClass, ...);
  */
 extern JS_PUBLIC_DATA(const JSClassOps) DefaultGlobalClassOps;
 
 } // namespace JS
 
+namespace JS {
+
+/**
+ * This allows easily constructing a global object without having to deal with
+ * JSClassOps, forgetting to add JS_GlobalObjectTraceHook, or forgetting to call
+ * JS::InitRealmStandardClasses(). Example:
+ *
+ *     const JSClass globalClass = { "MyGlobal", JSCLASS_GLOBAL_FLAGS,
+ *         &JS::DefaultGlobalClassOps };
+ *     JS_NewGlobalObject(cx, &globalClass, ...);
+ */
+extern JS_PUBLIC_DATA(const JSClassOps) DefaultGlobalClassOps;
+
+} // namespace JS
+
 extern JS_PUBLIC_API(void)
 JS_FireOnNewGlobalObject(JSContext* cx, JS::HandleObject global);
 
 extern JS_PUBLIC_API(JSObject*)
 JS_NewObject(JSContext* cx, const JSClass* clasp);
 
 extern JS_PUBLIC_API(bool)
 JS_IsNative(JSObject* obj);