Bug 1285927: Set wasm objects prototype only in the success path; r=luke
authorBenjamin Bouvier <benj@benj.me>
Tue, 12 Jul 2016 12:24:40 +0200
changeset 329735 1cabd2649c828c72783e96caa8e8edb3a0283ba5
parent 329734 56c832213c105136142a8979fc33f7e9883667e1
child 329736 430b90bebb96367ca5b1e53c435a1154009d383d
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1285927
milestone50.0a1
Bug 1285927: Set wasm objects prototype only in the success path; r=luke MozReview-Commit-ID: Il8v0XPLgoL
js/src/asmjs/WasmJS.cpp
--- a/js/src/asmjs/WasmJS.cpp
+++ b/js/src/asmjs/WasmJS.cpp
@@ -638,33 +638,35 @@ InitConstructor(JSContext* cx, HandleObj
 {
     RootedObject proto(cx, NewBuiltinClassInstance<PlainObject>(cx, SingletonObject));
     if (!proto)
         return false;
 
     if (!JS_DefineProperties(cx, proto, Class::properties))
         return false;
 
-    MOZ_ASSERT(global->as<GlobalObject>().getPrototype(Class::KEY).isUndefined());
-    global->as<GlobalObject>().setPrototype(Class::KEY, ObjectValue(*proto));
-
     RootedAtom className(cx, Atomize(cx, name, strlen(name)));
     if (!className)
         return false;
 
     RootedFunction ctor(cx, NewNativeConstructor(cx, native, 1, className));
     if (!ctor)
         return false;
 
     if (!LinkConstructorAndPrototype(cx, ctor, proto))
         return false;
 
     RootedId id(cx, AtomToId(className));
     RootedValue ctorValue(cx, ObjectValue(*ctor));
-    return DefineProperty(cx, wasm, id, ctorValue, nullptr, nullptr, 0);
+    if (!DefineProperty(cx, wasm, id, ctorValue, nullptr, nullptr, 0))
+        return false;
+
+    MOZ_ASSERT(global->as<GlobalObject>().getPrototype(Class::KEY).isUndefined());
+    global->as<GlobalObject>().setPrototype(Class::KEY, ObjectValue(*proto));
+    return true;
 }
 
 JSObject*
 js::InitWebAssemblyClass(JSContext* cx, HandleObject global)
 {
     MOZ_ASSERT(cx->options().wasm());
 
     RootedObject proto(cx, global->as<GlobalObject>().getOrCreateObjectPrototype(cx));