Bug 1134970 part 1. Add JS friend API to allocate an object which is guaranteed to have no attached metadata. r=waldo
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 24 Feb 2015 16:04:22 -0500
changeset 230598 0512c8c17930163fc91b9f0afe3e64f7f3028d1f
parent 230597 bf95ae9bfe5708671c43e7b1de08aae329a91b2d
child 230599 1a8fca17a4fab911cf9e0594a9f022295cd24700
push id28332
push usercbook@mozilla.com
push dateWed, 25 Feb 2015 11:06:35 +0000
treeherdermozilla-central@6608e0605dfc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswaldo
bugs1134970
milestone39.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 1134970 part 1. Add JS friend API to allocate an object which is guaranteed to have no attached metadata. r=waldo
js/src/jsfriendapi.cpp
js/src/jsfriendapi.h
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -140,16 +140,24 @@ JS_NewObjectWithUniqueType(JSContext *cx
                                                  parent, SingletonObject));
     if (!obj)
         return nullptr;
     if (!JS_SplicePrototype(cx, obj, proto))
         return nullptr;
     return obj;
 }
 
+JS_FRIEND_API(JSObject *)
+JS_NewObjectWithoutMetadata(JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto)
+{
+    // Use an AutoEnterAnalysis to suppress invocation of the metadata callback.
+    AutoEnterAnalysis enter(cx);
+    return JS_NewObjectWithGivenProto(cx, clasp, proto);
+}
+
 JS_FRIEND_API(JSPrincipals *)
 JS_GetCompartmentPrincipals(JSCompartment *compartment)
 {
     return compartment->principals;
 }
 
 JS_FRIEND_API(void)
 JS_SetCompartmentPrincipals(JSCompartment *compartment, JSPrincipals *principals)
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -55,16 +55,23 @@ JS_GetObjectFunction(JSObject *obj);
 
 extern JS_FRIEND_API(bool)
 JS_SplicePrototype(JSContext *cx, JS::HandleObject obj, JS::HandleObject proto);
 
 extern JS_FRIEND_API(JSObject *)
 JS_NewObjectWithUniqueType(JSContext *cx, const JSClass *clasp, JS::HandleObject proto,
                            JS::HandleObject parent);
 
+// Allocate an object in exactly the same way as JS_NewObjectWithGivenProto, but
+// without invoking the metadata callback on it.  This allows creation of
+// internal bookkeeping objects that are guaranteed to not have metadata
+// attached to them.
+extern JS_FRIEND_API(JSObject *)
+JS_NewObjectWithoutMetadata(JSContext *cx, const JSClass *clasp, JS::Handle<JSObject*> proto);
+
 extern JS_FRIEND_API(uint32_t)
 JS_ObjectCountDynamicSlots(JS::HandleObject obj);
 
 extern JS_FRIEND_API(size_t)
 JS_SetProtoCalled(JSContext *cx);
 
 extern JS_FRIEND_API(size_t)
 JS_GetCustomIteratorCount(JSContext *cx);