diff --git a/dom/serviceworkers/test/test_serviceworker_interfaces.js b/dom/serviceworkers/test/test_serviceworker_interfaces.js index 34ea757a56c8..4ae800b126f8 100644 --- a/dom/serviceworkers/test/test_serviceworker_interfaces.js +++ b/dom/serviceworkers/test/test_serviceworker_interfaces.js @@ -67,7 +67,6 @@ var ecmaGlobals = [ "String", "Symbol", "SyntaxError", - { name: "TypedObject", nightly: true }, "TypeError", "Uint16Array", "Uint32Array", diff --git a/dom/tests/mochitest/general/test_interfaces.js b/dom/tests/mochitest/general/test_interfaces.js index 1087b1227211..2d09a426590f 100644 --- a/dom/tests/mochitest/general/test_interfaces.js +++ b/dom/tests/mochitest/general/test_interfaces.js @@ -96,7 +96,6 @@ var ecmaGlobals = [ { name: "String", insecureContext: true }, { name: "Symbol", insecureContext: true }, { name: "SyntaxError", insecureContext: true }, - { name: "TypedObject", insecureContext: true, nightly: true }, { name: "TypeError", insecureContext: true }, { name: "Uint16Array", insecureContext: true }, { name: "Uint32Array", insecureContext: true }, diff --git a/dom/workers/test/test_worker_interfaces.js b/dom/workers/test/test_worker_interfaces.js index f08d86bd2c8f..164315d1764b 100644 --- a/dom/workers/test/test_worker_interfaces.js +++ b/dom/workers/test/test_worker_interfaces.js @@ -76,7 +76,6 @@ var ecmaGlobals = [ { name: "String", insecureContext: true }, { name: "Symbol", insecureContext: true }, { name: "SyntaxError", insecureContext: true }, - { name: "TypedObject", insecureContext: true, nightly: true }, { name: "TypeError", insecureContext: true }, { name: "Uint16Array", insecureContext: true }, { name: "Uint32Array", insecureContext: true }, diff --git a/js/moz.configure b/js/moz.configure index 3e90863b2fa5..39d8e67da395 100644 --- a/js/moz.configure +++ b/js/moz.configure @@ -494,22 +494,6 @@ option('--enable-wasm-codegen-debug', set_config('WASM_CODEGEN_DEBUG', depends_if('--enable-wasm-codegen-debug')(lambda x: True)) set_define('WASM_CODEGEN_DEBUG', depends_if('--enable-wasm-codegen-debug')(lambda x: True)) - -# Support for typed objects. -# ===================================================== - -@depends(milestone.is_nightly) -def default_typed_objects(is_nightly): - return is_nightly - -option('--enable-typed-objects', - default=default_typed_objects, - help='{Enable|Disable} typed objects') - -set_config('JS_HAS_TYPED_OBJECTS', depends_if('--enable-typed-objects')(lambda x: True)) -set_define('JS_HAS_TYPED_OBJECTS', depends_if('--enable-typed-objects')(lambda x: True)) - - # Support for WebAssembly reference types. # ===================================================== @@ -552,24 +536,24 @@ set_define('ENABLE_WASM_FUNCTION_REFERENCES', wasm_function_references) # Support for WebAssembly GC. # =========================== -@depends(milestone.is_nightly, '--enable-wasm-function-references', '--enable-typed-objects') -def default_wasm_gc(is_nightly, function_references, typed_objects): - if is_nightly and function_references and typed_objects: +@depends(milestone.is_nightly, '--enable-wasm-function-references') +def default_wasm_gc(is_nightly, function_references): + if is_nightly and function_references: return True option('--enable-wasm-gc', default=default_wasm_gc, help='{Enable|Disable} WebAssembly GC') -@depends('--enable-wasm-gc', '--enable-wasm-function-references', '--enable-typed-objects') -def wasm_gc(value, function_references, typed_objects): +@depends('--enable-wasm-gc', '--enable-wasm-function-references') +def wasm_gc(value, function_references): if not value: return - if function_references and typed_objects: + if function_references: return True - die('--enable-wasm-gc only possible with --enable-wasm-function-references and --enable-typed-objects') + die('--enable-wasm-gc only possible with --enable-wasm-function-references') set_config('ENABLE_WASM_GC', wasm_gc) set_define('ENABLE_WASM_GC', wasm_gc) diff --git a/js/public/ProtoKey.h b/js/public/ProtoKey.h index b8f4a44624cd..c9dbd6ed9011 100644 --- a/js/public/ProtoKey.h +++ b/js/public/ProtoKey.h @@ -40,13 +40,7 @@ # define IF_INTL(REAL, IMAGINARY) IMAGINARY #endif -#ifdef JS_HAS_TYPED_OBJECTS -# define IF_TYPEDOBJ(REAL, IMAGINARY) REAL -#else -# define IF_TYPEDOBJ(REAL, IMAGINARY) IMAGINARY -#endif - -#define JS_FOR_PROTOTYPES_(REAL, IMAGINARY, REAL_IF_INTL, REAL_IF_BDATA) \ +#define JS_FOR_PROTOTYPES_(REAL, IMAGINARY, REAL_IF_INTL) \ IMAGINARY(Null, dummy) \ REAL(Object, OCLASP(Plain)) \ REAL(Function, &JSFunction::class_) \ @@ -100,7 +94,6 @@ REAL_IF_INTL(NumberFormat, OCLASP(NumberFormat)) \ REAL_IF_INTL(PluralRules, OCLASP(PluralRules)) \ REAL_IF_INTL(RelativeTimeFormat, OCLASP(RelativeTimeFormat)) \ - REAL_IF_BDATA(TypedObject, OCLASP(TypedObjectModule)) \ REAL(Reflect, CLASP(Reflect)) \ REAL(WeakSet, OCLASP(WeakSet)) \ REAL(TypedArray, &js::TypedArrayObject::sharedTypedArrayPrototypeClass) \ @@ -122,7 +115,7 @@ REAL(WritableStreamDefaultWriter, &js::WritableStreamDefaultWriter::class_) \ REAL(ByteLengthQueuingStrategy, &js::ByteLengthQueuingStrategy::class_) \ REAL(CountQueuingStrategy, &js::CountQueuingStrategy::class_) \ - REAL(WebAssembly, CLASP(WebAssembly)) \ + REAL(WebAssembly, OCLASP(WasmNamespace)) \ REAL(WasmModule, OCLASP(WasmModule)) \ REAL(WasmInstance, OCLASP(WasmInstance)) \ REAL(WasmMemory, OCLASP(WasmMemory)) \ @@ -133,9 +126,8 @@ REAL(Iterator, OCLASP(Iterator)) \ REAL(AsyncIterator, OCLASP(AsyncIterator)) -#define JS_FOR_PROTOTYPES(REAL, IMAGINARY) \ - JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY), \ - IF_TYPEDOBJ(REAL, IMAGINARY)) +#define JS_FOR_PROTOTYPES(REAL, IMAGINARY) \ + JS_FOR_PROTOTYPES_(REAL, IMAGINARY, IF_INTL(REAL, IMAGINARY)) #define JS_FOR_EACH_PROTOTYPE(MACRO) JS_FOR_PROTOTYPES(MACRO, MACRO) diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index 2cc64234d409..902417cf9343 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -452,15 +452,6 @@ static bool GetBuildConfiguration(JSContext* cx, unsigned argc, Value* vp) { return false; } -#ifdef JS_HAS_TYPED_OBJECTS - value = BooleanValue(true); -#else - value = BooleanValue(false); -#endif - if (!JS_SetProperty(cx, info, "typed-objects", value)) { - return false; - } - #ifdef JS_HAS_INTL_API value = BooleanValue(true); #else diff --git a/js/src/js-config.h.in b/js/src/js-config.h.in index 6276e0c7decc..b54f1bc2cb90 100644 --- a/js/src/js-config.h.in +++ b/js/src/js-config.h.in @@ -35,9 +35,6 @@ /* Define to 1 if SpiderMonkey should include trace logging support. */ #undef JS_TRACE_LOGGING -/* Define to 1 if SpiderMonkey should include typed objects support. */ -#undef JS_HAS_TYPED_OBJECTS - /* Define to 1 if SpiderMonkey should include support for the Intl API. */ #undef JS_HAS_INTL_API diff --git a/js/src/vm/GlobalObject.cpp b/js/src/vm/GlobalObject.cpp index 7350b3a23e24..bb661440e228 100644 --- a/js/src/vm/GlobalObject.cpp +++ b/js/src/vm/GlobalObject.cpp @@ -57,9 +57,6 @@ #include "vm/PIC.h" #include "vm/RegExpStatics.h" #include "vm/RegExpStaticsObject.h" -#ifdef JS_HAS_TYPED_OBJECTS -# include "wasm/TypedObject.h" -#endif #include "gc/FreeOp-inl.h" #include "vm/JSObject-inl.h" @@ -75,7 +72,6 @@ extern const JSClass IntlClass; extern const JSClass JSONClass; extern const JSClass MathClass; extern const JSClass ReflectClass; -extern const JSClass WebAssemblyClass; } // namespace js @@ -93,13 +89,13 @@ JS_FRIEND_API const JSClass* js::ProtoKeyToClass(JSProtoKey key) { } // This method is not in the header file to avoid having to include -// TypedObject.h from GlobalObject.h. It is not generally perf +// WasmJS.h from GlobalObject.h. It is not generally perf // sensitive. -TypedObjectModuleObject& js::GlobalObject::getTypedObjectModule() const { - Value v = getConstructor(JSProto_TypedObject); - // only gets called from contexts where TypedObject must be initialized +WasmNamespaceObject& js::GlobalObject::getWebAssemblyNamespace() const { + Value v = getConstructor(JSProto_WebAssembly); + // only gets called from contexts where WebAssembly must be initialized MOZ_ASSERT(v.isObject()); - return v.toObject().as(); + return v.toObject().as(); } /* static */ @@ -181,11 +177,6 @@ bool GlobalObject::skipDeselectedConstructor(JSContext* cx, JSProtoKey key) { return false; #endif -#ifdef JS_HAS_TYPED_OBJECTS - case JSProto_TypedObject: - return false; -#endif - case JSProto_ReadableStream: case JSProto_ReadableStreamDefaultReader: case JSProto_ReadableStreamDefaultController: diff --git a/js/src/vm/GlobalObject.h b/js/src/vm/GlobalObject.h index 9a55c32d5de1..5f327dafe087 100644 --- a/js/src/vm/GlobalObject.h +++ b/js/src/vm/GlobalObject.h @@ -55,7 +55,7 @@ class LexicalEnvironmentObject; class PlainObject; class RegExpStatics; class TypeDescr; -class TypedObjectModuleObject; +class WasmNamespaceObject; enum class ReferenceType; @@ -500,9 +500,9 @@ class GlobalObject : public NativeObject { return &global->getPrototype(JSProto_WeakSet).toObject().as(); } - static JSObject* getOrCreateTypedObjectModule(JSContext* cx, - Handle global) { - return getOrCreateConstructor(cx, JSProto_TypedObject); + static JSObject* getOrCreateWebAssemblyNamespace( + JSContext* cx, Handle global) { + return getOrCreateConstructor(cx, JSProto_WebAssembly); } static TypeDescr* getOrCreateScalarTypeDescr(JSContext* cx, @@ -513,7 +513,7 @@ class GlobalObject : public NativeObject { Handle global, ReferenceType type); - TypedObjectModuleObject& getTypedObjectModule() const; + WasmNamespaceObject& getWebAssemblyNamespace() const; static bool ensureModulePrototypesCreated(JSContext* cx, Handle global); @@ -873,10 +873,6 @@ class GlobalObject : public NativeObject { static bool initRequestedModuleProto(JSContext* cx, Handle global); - // Implemented in wasm/TypedObject.cpp - static bool initTypedObjectModule(JSContext* cx, - Handle global); - static bool initStandardClasses(JSContext* cx, Handle global); static bool initSelfHostingBuiltins(JSContext* cx, Handle global, diff --git a/js/src/wasm/TypedObject.cpp b/js/src/wasm/TypedObject.cpp index 4dbff800346c..819a433296dd 100644 --- a/js/src/wasm/TypedObject.cpp +++ b/js/src/wasm/TypedObject.cpp @@ -27,6 +27,7 @@ #include "vm/TypedArrayObject.h" #include "vm/Uint8Clamped.h" +#include "wasm/WasmJS.h" // WasmNamespaceObject #include "wasm/WasmTypes.h" // WasmValueBox #include "gc/Marking-inl.h" #include "gc/Nursery-inl.h" @@ -44,12 +45,6 @@ using mozilla::PointerRangeSize; using namespace js; -const JSClass js::TypedObjectModuleObject::class_ = { - "TypedObject", - JSCLASS_HAS_RESERVED_SLOTS(SlotCount) | - JSCLASS_HAS_CACHED_PROTO(JSProto_TypedObject), - JS_NULL_CLASS_OPS, &classSpec_}; - template static inline T* ToObjectIf(HandleValue value) { if (!value.isObject()) { @@ -236,28 +231,28 @@ TypeDescr* GlobalObject::getOrCreateScalarTypeDescr( int32_t slot = 0; switch (scalarType) { case Scalar::Int32: - slot = TypedObjectModuleObject::Int32Desc; + slot = WasmNamespaceObject::Int32Desc; break; case Scalar::Int64: - slot = TypedObjectModuleObject::Int64Desc; + slot = WasmNamespaceObject::Int64Desc; break; case Scalar::Float32: - slot = TypedObjectModuleObject::Float32Desc; + slot = WasmNamespaceObject::Float32Desc; break; case Scalar::Float64: - slot = TypedObjectModuleObject::Float64Desc; + slot = WasmNamespaceObject::Float64Desc; break; default: MOZ_CRASH("NYI"); } - Rooted module( - cx, &GlobalObject::getOrCreateTypedObjectModule(cx, global) - ->as()); - if (!module) { + Rooted namespaceObject( + cx, &GlobalObject::getOrCreateWebAssemblyNamespace(cx, global) + ->as()); + if (!namespaceObject) { return nullptr; } - return &module->getReservedSlot(slot).toObject().as(); + return &namespaceObject->getReservedSlot(slot).toObject().as(); } /* static */ @@ -266,22 +261,22 @@ TypeDescr* GlobalObject::getOrCreateReferenceTypeDescr( int32_t slot = 0; switch (type) { case ReferenceType::TYPE_OBJECT: - slot = TypedObjectModuleObject::ObjectDesc; + slot = WasmNamespaceObject::ObjectDesc; break; case ReferenceType::TYPE_WASM_ANYREF: - slot = TypedObjectModuleObject::WasmAnyRefDesc; + slot = WasmNamespaceObject::WasmAnyRefDesc; break; default: MOZ_CRASH("NYI"); } - Rooted module( - cx, &GlobalObject::getOrCreateTypedObjectModule(cx, global) - ->as()); - if (!module) { + Rooted namespaceObject( + cx, &GlobalObject::getOrCreateWebAssemblyNamespace(cx, global) + ->as()); + if (!namespaceObject) { return nullptr; } - return &module->getReservedSlot(slot).toObject().as(); + return &namespaceObject->getReservedSlot(slot).toObject().as(); } /*************************************************************************** @@ -849,7 +844,8 @@ TypeDescr& StructTypeDescr::fieldDescr(size_t index) const { // Here `T` is either `ScalarTypeDescr` or `ReferenceTypeDescr` template static bool DefineSimpleTypeDescr(JSContext* cx, Handle global, - HandleObject module, typename T::Type type, + Handle namespaceObject, + typename T::Type type, HandlePropertyName className) { RootedObject objProto(cx, GlobalObject::getOrCreateObjectPrototype(cx, global)); @@ -885,7 +881,7 @@ static bool DefineSimpleTypeDescr(JSContext* cx, Handle global, descr->initReservedSlot(TypeDescr::Proto, ObjectValue(*proto)); RootedValue descrValue(cx, ObjectValue(*descr)); - if (!DefineDataProperty(cx, module, className, descrValue, 0)) { + if (!DefineDataProperty(cx, namespaceObject, className, descrValue, 0)) { return false; } @@ -903,10 +899,10 @@ static bool DefineSimpleTypeDescr(JSContext* cx, Handle global, /////////////////////////////////////////////////////////////////////////// template -static JSObject* DefineMetaTypeDescr(JSContext* cx, const char* name, - Handle global, - Handle module, - TypedObjectModuleObject::Slot protoSlot) { +static JSObject* DefineMetaTypeDescr( + JSContext* cx, const char* name, Handle global, + Handle namespaceObject, + WasmNamespaceObject::Slot protoSlot) { RootedAtom className(cx, Atomize(cx, name, strlen(name))); if (!className) { return nullptr; @@ -926,46 +922,27 @@ static JSObject* DefineMetaTypeDescr(JSContext* cx, const char* name, return nullptr; } - module->initReservedSlot(protoSlot, ObjectValue(*proto)); + namespaceObject->initReservedSlot(protoSlot, ObjectValue(*proto)); return ctor; } -static JSObject* CreateTypedObjectModuleObject(JSContext* cx, JSProtoKey key) { - Handle global = cx->global(); - RootedObject objProto(cx, - GlobalObject::getOrCreateObjectPrototype(cx, global)); - if (!objProto) { - return nullptr; - } - - return NewSingletonObjectWithGivenProto(cx, - objProto); -} - -/* The initialization strategy for TypedObjects is mildly unusual - * compared to other classes. Because all of the types are members - * of a single global, `TypedObject`, we basically make the - * initializer for the `TypedObject` class populate the - * `TypedObject` global (which is referred to as "module" herein). - */ -static bool TypedObjectModuleObjectClassFinish(JSContext* cx, HandleObject ctor, - HandleObject proto) { - Handle module = ctor.as(); +bool js::InitTypedObjectNamespace( + JSContext* cx, Handle namespaceObject) { Handle global = cx->global(); // uint8, uint16, any, etc #define BINARYDATA_SCALAR_DEFINE(constant_, type_, name_) \ - if (!DefineSimpleTypeDescr(cx, global, module, constant_, \ - cx->names().name_)) \ + if (!DefineSimpleTypeDescr(cx, global, namespaceObject, \ + constant_, cx->names().name_)) \ return false; JS_FOR_EACH_SCALAR_TYPE_REPR(BINARYDATA_SCALAR_DEFINE) #undef BINARYDATA_SCALAR_DEFINE -#define BINARYDATA_REFERENCE_DEFINE(constant_, type_, name_) \ - if (!DefineSimpleTypeDescr( \ - cx, global, module, constant_, cx->names().name_)) \ +#define BINARYDATA_REFERENCE_DEFINE(constant_, type_, name_) \ + if (!DefineSimpleTypeDescr( \ + cx, global, namespaceObject, constant_, cx->names().name_)) \ return false; JS_FOR_EACH_REFERENCE_TYPE_REPR(BINARYDATA_REFERENCE_DEFINE) #undef BINARYDATA_REFERENCE_DEFINE @@ -978,49 +955,52 @@ static bool TypedObjectModuleObjectClassFinish(JSContext* cx, HandleObject ctor, // JS_GetProperty(). The properties themselves will always exist on the // object. - if (!JS_GetProperty(cx, module, "int32", &typeDescr)) { + if (!JS_GetProperty(cx, namespaceObject, "int32", &typeDescr)) { return false; } - module->initReservedSlot(TypedObjectModuleObject::Int32Desc, typeDescr); + namespaceObject->initReservedSlot(WasmNamespaceObject::Int32Desc, typeDescr); - if (!JS_GetProperty(cx, module, "int64", &typeDescr)) { + if (!JS_GetProperty(cx, namespaceObject, "int64", &typeDescr)) { return false; } - module->initReservedSlot(TypedObjectModuleObject::Int64Desc, typeDescr); + namespaceObject->initReservedSlot(WasmNamespaceObject::Int64Desc, typeDescr); - if (!JS_GetProperty(cx, module, "float32", &typeDescr)) { + if (!JS_GetProperty(cx, namespaceObject, "float32", &typeDescr)) { return false; } - module->initReservedSlot(TypedObjectModuleObject::Float32Desc, typeDescr); + namespaceObject->initReservedSlot(WasmNamespaceObject::Float32Desc, + typeDescr); - if (!JS_GetProperty(cx, module, "float64", &typeDescr)) { + if (!JS_GetProperty(cx, namespaceObject, "float64", &typeDescr)) { return false; } - module->initReservedSlot(TypedObjectModuleObject::Float64Desc, typeDescr); + namespaceObject->initReservedSlot(WasmNamespaceObject::Float64Desc, + typeDescr); - if (!JS_GetProperty(cx, module, "Object", &typeDescr)) { + if (!JS_GetProperty(cx, namespaceObject, "Object", &typeDescr)) { return false; } - module->initReservedSlot(TypedObjectModuleObject::ObjectDesc, typeDescr); + namespaceObject->initReservedSlot(WasmNamespaceObject::ObjectDesc, typeDescr); - if (!JS_GetProperty(cx, module, "WasmAnyRef", &typeDescr)) { + if (!JS_GetProperty(cx, namespaceObject, "WasmAnyRef", &typeDescr)) { return false; } - module->initReservedSlot(TypedObjectModuleObject::WasmAnyRefDesc, typeDescr); + namespaceObject->initReservedSlot(WasmNamespaceObject::WasmAnyRefDesc, + typeDescr); // ArrayType. RootedObject arrayType(cx); arrayType = DefineMetaTypeDescr( - cx, "ArrayType", global, module, - TypedObjectModuleObject::ArrayTypePrototype); + cx, "ArrayType", global, namespaceObject, + WasmNamespaceObject::ArrayTypePrototype); if (!arrayType) { return false; } RootedValue arrayTypeValue(cx, ObjectValue(*arrayType)); - if (!DefineDataProperty(cx, module, cx->names().ArrayType, arrayTypeValue, - JSPROP_READONLY | JSPROP_PERMANENT)) { + if (!DefineDataProperty(cx, namespaceObject, cx->names().ArrayType, + arrayTypeValue, JSPROP_READONLY | JSPROP_PERMANENT)) { return false; } @@ -1028,14 +1008,15 @@ static bool TypedObjectModuleObjectClassFinish(JSContext* cx, HandleObject ctor, RootedObject structType(cx); structType = DefineMetaTypeDescr( - cx, "StructType", global, module, - TypedObjectModuleObject::StructTypePrototype); + cx, "StructType", global, namespaceObject, + WasmNamespaceObject::StructTypePrototype); if (!structType) { return false; } RootedValue structTypeValue(cx, ObjectValue(*structType)); - if (!DefineDataProperty(cx, module, cx->names().StructType, structTypeValue, + if (!DefineDataProperty(cx, namespaceObject, cx->names().StructType, + structTypeValue, JSPROP_READONLY | JSPROP_PERMANENT)) { return false; } @@ -1043,15 +1024,6 @@ static bool TypedObjectModuleObjectClassFinish(JSContext* cx, HandleObject ctor, return true; } -const ClassSpec TypedObjectModuleObject::classSpec_ = { - CreateTypedObjectModuleObject, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - TypedObjectModuleObjectClassFinish}; - TypedProto* TypedProto::create(JSContext* cx) { Handle global = cx->global(); RootedObject objProto(cx, diff --git a/js/src/wasm/TypedObject.h b/js/src/wasm/TypedObject.h index c40f394edb0e..e561a110bac3 100644 --- a/js/src/wasm/TypedObject.h +++ b/js/src/wasm/TypedObject.h @@ -20,6 +20,11 @@ namespace js { +class WasmNamespaceObject; + +extern bool InitTypedObjectNamespace( + JSContext* cx, Handle namespaceObject); + /* The prototype for typed objects. */ class TypedProto : public NativeObject { public: @@ -344,31 +349,6 @@ class StructTypeDescr : public ComplexTypeDescr { using HandleStructTypeDescr = Handle; -/* - * This object exists in order to encapsulate the typed object types - * somewhat, rather than sticking them all into the global object. - * Eventually it will go away and become a module. - */ -class TypedObjectModuleObject : public NativeObject { - public: - enum Slot { - ArrayTypePrototype, - StructTypePrototype, - Int32Desc, - Int64Desc, - Float32Desc, - Float64Desc, - ObjectDesc, - WasmAnyRefDesc, - SlotCount - }; - - static const JSClass class_; - - private: - static const ClassSpec classSpec_; -}; - /* Base type for typed objects. */ class TypedObject : public JSObject { static MOZ_MUST_USE bool obj_getArrayElement(JSContext* cx, diff --git a/js/src/wasm/WasmJS.cpp b/js/src/wasm/WasmJS.cpp index 1602db4b58ed..caa9610175c3 100644 --- a/js/src/wasm/WasmJS.cpp +++ b/js/src/wasm/WasmJS.cpp @@ -4316,11 +4316,14 @@ static JSObject* CreateWebAssemblyObject(JSContext* cx, JSProtoKey key) { if (!proto) { return nullptr; } - return NewSingletonObjectWithGivenProto(cx, &WebAssemblyClass, proto); + return NewSingletonObjectWithGivenProto(cx, &WasmNamespaceObject::class_, + proto); } -static bool WebAssemblyClassFinish(JSContext* cx, HandleObject wasm, +static bool WebAssemblyClassFinish(JSContext* cx, HandleObject object, HandleObject proto) { + Handle wasm = object.as(); + struct NameAndProtoKey { const char* const name; JSProtoKey key; @@ -4360,6 +4363,10 @@ static bool WebAssemblyClassFinish(JSContext* cx, HandleObject wasm, } } + if (GcTypesAvailable(cx) && !InitTypedObjectNamespace(cx, wasm)) { + return false; + } + return true; } @@ -4371,6 +4378,8 @@ static const ClassSpec WebAssemblyClassSpec = {CreateWebAssemblyObject, nullptr, WebAssemblyClassFinish}; -const JSClass js::WebAssemblyClass = { - js_WebAssembly_str, JSCLASS_HAS_CACHED_PROTO(JSProto_WebAssembly), +const JSClass js::WasmNamespaceObject::class_ = { + js_WebAssembly_str, + JSCLASS_HAS_RESERVED_SLOTS(SlotCount) | + JSCLASS_HAS_CACHED_PROTO(JSProto_WebAssembly), JS_NULL_CLASS_OPS, &WebAssemblyClassSpec}; diff --git a/js/src/wasm/WasmJS.h b/js/src/wasm/WasmJS.h index c140b631554f..debf9abc250b 100644 --- a/js/src/wasm/WasmJS.h +++ b/js/src/wasm/WasmJS.h @@ -184,10 +184,6 @@ MOZ_MUST_USE bool CheckRefType(JSContext* cx, RefType targetType, HandleValue v, } // namespace wasm -// The class of the WebAssembly global namespace object. - -extern const JSClass WebAssemblyClass; - // The class of WebAssembly.Module. Each WasmModuleObject owns a // wasm::Module. These objects are used both as content-facing JS objects and as // internal implementation details of asm.js. @@ -457,6 +453,28 @@ class WasmTableObject : public NativeObject { wasm::Table& table() const; }; +// The class of the WebAssembly global namespace object. + +class WasmNamespaceObject : public NativeObject { + public: + enum Slot { + ArrayTypePrototype, + StructTypePrototype, + Int32Desc, + Int64Desc, + Float32Desc, + Float64Desc, + ObjectDesc, + WasmAnyRefDesc, + SlotCount + }; + + static const JSClass class_; + + private: + static const ClassSpec classSpec_; +}; + } // namespace js #endif // wasm_js_h diff --git a/js/src/wasm/WasmModule.cpp b/js/src/wasm/WasmModule.cpp index 2b2fc1eb4232..80fa3ded41b7 100644 --- a/js/src/wasm/WasmModule.cpp +++ b/js/src/wasm/WasmModule.cpp @@ -1244,23 +1244,18 @@ bool Module::makeStructTypeDescrs( MOZ_CRASH("Should not have seen any struct types"); #else -# ifndef JS_HAS_TYPED_OBJECTS -# error "GC types require TypedObject" -# endif - // Not just any prototype object will do, we must have the actual // StructTypePrototype. - RootedObject typedObjectModule( - cx, GlobalObject::getOrCreateTypedObjectModule(cx, cx->global())); - if (!typedObjectModule) { + RootedObject namespaceObject( + cx, GlobalObject::getOrCreateWebAssemblyNamespace(cx, cx->global())); + if (!namespaceObject) { return false; } - RootedNativeObject toModule(cx, &typedObjectModule->as()); + RootedNativeObject toModule(cx, &namespaceObject->as()); RootedObject prototype( - cx, - &toModule->getReservedSlot(TypedObjectModuleObject::StructTypePrototype) - .toObject()); + cx, &toModule->getReservedSlot(WasmNamespaceObject::StructTypePrototype) + .toObject()); for (const StructType& structType : structTypes()) { RootedIdVector ids(cx);