Bug 946906 part 3. Create a macro for declaring Xray expando classes, and move the default Xray expand class definition to bindings code. r=bholley
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 10 Oct 2016 18:16:25 -0400
changeset 360197 802ef473a08323491e4ae944e605bfbd7f16442d
parent 360196 0a0046d3e726896f247d88c82363a6a061f5f0ff
child 360198 01ab3f3823d5964019cf3033f5b875b6d8a3876a
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-beta@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs946906
milestone52.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 946906 part 3. Create a macro for declaring Xray expando classes, and move the default Xray expand class definition to bindings code. r=bholley
dom/bindings/BindingUtils.cpp
dom/bindings/XrayExpandoClass.h
dom/bindings/moz.build
js/xpconnect/wrappers/XrayWrapper.cpp
--- a/dom/bindings/BindingUtils.cpp
+++ b/dom/bindings/BindingUtils.cpp
@@ -46,16 +46,17 @@
 #include "mozilla/dom/HTMLSharedObjectElement.h"
 #include "mozilla/dom/HTMLEmbedElementBinding.h"
 #include "mozilla/dom/HTMLAppletElementBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/ResolveSystemBinding.h"
 #include "mozilla/dom/WebIDLGlobalNameHash.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/WorkerScope.h"
+#include "mozilla/dom/XrayExpandoClass.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
 #include "nsDOMClassInfo.h"
 #include "ipc/ErrorIPCUtils.h"
 #include "mozilla/UseCounter.h"
 
 namespace mozilla {
 namespace dom {
 
@@ -1887,16 +1888,18 @@ XrayOwnPropertyKeys(JSContext* cx, JS::H
     }
   }
 
   return type == eGlobalInterfacePrototype ||
          XrayOwnNativePropertyKeys(cx, wrapper, nativePropertyHooks, type,
                                    obj, flags, props);
 }
 
+DEFINE_XRAY_EXPANDO_CLASS(, DefaultXrayExpandoObjectClass, 0);
+
 NativePropertyHooks sEmptyNativePropertyHooks = {
   nullptr,
   nullptr,
   {
     nullptr,
     nullptr
   },
   prototypes::id::_ID_Count,
new file mode 100644
--- /dev/null
+++ b/dom/bindings/XrayExpandoClass.h
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * This file declares a macro for defining Xray expando classes and declares the
+ * default Xray expando class.  The actual definition of that default class
+ * lives elsewhere.
+ */
+#ifndef mozilla_dom_XrayExpandoClass_h
+#define mozilla_dom_XrayExpandoClass_h
+
+/*
+ * maybeStatic_ Should be either `static` or nothing (because some Xray expando
+ * classes are not static).
+ *
+ * name_ should be the name of the variable.
+ *
+ * extraSlots_ should be how many extra slots to give the class, in addition to
+ * the ones Xray expandos want.
+ */
+#define DEFINE_XRAY_EXPANDO_CLASS(maybeStatic_, name_, extraSlots_)	\
+  maybeStatic_ const JSClass name_ = {					\
+    "XrayExpandoObject",						\
+    JSCLASS_HAS_RESERVED_SLOTS(xpc::JSSLOT_EXPANDO_COUNT +		\
+			       (extraSlots_)) |				\
+    JSCLASS_FOREGROUND_FINALIZE,					\
+    &xpc::XrayExpandoObjectClassOps					\
+  }
+
+namespace mozilla {
+namespace dom {
+
+extern const JSClass DefaultXrayExpandoObjectClass;
+
+} // namespace mozilla
+} // namespace dom
+
+#endif /* mozilla_dom_XrayExpandoClass_h */
--- a/dom/bindings/moz.build
+++ b/dom/bindings/moz.build
@@ -38,16 +38,17 @@ EXPORTS.mozilla.dom += [
     'PrimitiveConversions.h',
     'RootedDictionary.h',
     'SimpleGlobalObject.h',
     'StructuredClone.h',
     'ToJSValue.h',
     'TypedArray.h',
     'UnionMember.h',
     'WebIDLGlobalNameHash.h',
+    'XrayExpandoClass.h',
 ]
 
 # Generated bindings reference *Binding.h, not mozilla/dom/*Binding.h. And,
 # since we generate exported bindings directly to $(DIST)/include, we need
 # to add that path to the search list.
 #
 # Ideally, binding generation uses the prefixed header file names.
 # Bug 932082 tracks.
--- a/js/xpconnect/wrappers/XrayWrapper.cpp
+++ b/js/xpconnect/wrappers/XrayWrapper.cpp
@@ -17,16 +17,17 @@
 
 #include "jsapi.h"
 #include "jsprf.h"
 #include "nsJSUtils.h"
 #include "nsPrintfCString.h"
 
 #include "mozilla/dom/BindingUtils.h"
 #include "mozilla/dom/WindowBinding.h"
+#include "mozilla/dom/XrayExpandoClass.h"
 #include "nsGlobalWindow.h"
 
 using namespace mozilla::dom;
 using namespace JS;
 using namespace mozilla;
 
 using js::Wrapper;
 using js::BaseProxyHandler;
@@ -1055,23 +1056,16 @@ ExpandoObjectFinalize(JSFreeOp* fop, JSO
     NS_RELEASE(principal);
 }
 
 const JSClassOps XrayExpandoObjectClassOps = {
     nullptr, nullptr, nullptr, nullptr,
     nullptr, nullptr, nullptr, ExpandoObjectFinalize
 };
 
-const JSClass ExpandoObjectClass = {
-    "XrayExpandoObject",
-    JSCLASS_HAS_RESERVED_SLOTS(JSSLOT_EXPANDO_COUNT) |
-    JSCLASS_FOREGROUND_FINALIZE,
-    &XrayExpandoObjectClassOps
-};
-
 bool
 XrayTraits::expandoObjectMatchesConsumer(JSContext* cx,
                                          HandleObject expandoObject,
                                          nsIPrincipal* consumerOrigin,
                                          HandleObject exclusiveGlobal)
 {
     MOZ_ASSERT(js::IsObjectInContextCompartment(expandoObject, cx));
 
@@ -1157,17 +1151,17 @@ XrayTraits::attachExpandoObject(JSContex
             MOZ_ASSERT(!existingExpandoObject);
         else
             JS_ClearPendingException(cx);
     }
 #endif
 
     // Create the expando object.
     RootedObject expandoObject(cx,
-      JS_NewObjectWithGivenProto(cx, &ExpandoObjectClass, nullptr));
+      JS_NewObjectWithGivenProto(cx, &DefaultXrayExpandoObjectClass, nullptr));
     if (!expandoObject)
         return nullptr;
 
     // AddRef and store the principal.
     NS_ADDREF(origin);
     JS_SetReservedSlot(expandoObject, JSSLOT_EXPANDO_ORIGIN, JS::PrivateValue(origin));
 
     // Note the exclusive global, if any.