From 259c1c815bef5be18722910a2652684059851b86 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Wed, 22 Jun 2022 17:55:18 -0700 Subject: [PATCH] Cherry-pick bugfix for ReadableByteStream --- JSTests/stress/typed-array-builtin-names.js | 29 +++++++++++++++++++ .../bytecode/LinkTimeConstant.h | 11 +++++++ .../JavaScriptCore/runtime/JSGlobalObject.cpp | 4 ++- 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 JSTests/stress/typed-array-builtin-names.js diff --git a/JSTests/stress/typed-array-builtin-names.js b/JSTests/stress/typed-array-builtin-names.js new file mode 100644 index 0000000000000..2b8f8f046a171 --- /dev/null +++ b/JSTests/stress/typed-array-builtin-names.js @@ -0,0 +1,29 @@ +var createBuiltin = $vm.createBuiltin; + +function shouldBe(actual, expected) { + if (actual !== expected) + throw new Error('bad value: ' + actual); +} + +let list = [ + "Int8Array", + "Uint8Array", + "Uint8ClampedArray", + "Int16Array", + "Uint16Array", + "Int32Array", + "Uint32Array", + "Float32Array", + "Float64Array", + "BigInt64Array", + "BigUint64Array", +]; + +for (let constructorName of list) { + let builtin = createBuiltin(`(function (a) { + return @${constructorName}; + })`); + let constructor = builtin(); + shouldBe(constructor.name, constructorName); + shouldBe(constructor, globalThis[constructorName]); +} diff --git a/Source/JavaScriptCore/bytecode/LinkTimeConstant.h b/Source/JavaScriptCore/bytecode/LinkTimeConstant.h index b8653e8656993..8324efc57d7ef 100644 --- a/Source/JavaScriptCore/bytecode/LinkTimeConstant.h +++ b/Source/JavaScriptCore/bytecode/LinkTimeConstant.h @@ -123,6 +123,17 @@ class JSGlobalObject; v(jsonParse, nullptr) \ v(jsonStringify, nullptr) \ v(String, nullptr) \ + v(Int8Array, nullptr) \ + v(Uint8Array, nullptr) \ + v(Uint8ClampedArray, nullptr) \ + v(Int16Array, nullptr) \ + v(Uint16Array, nullptr) \ + v(Int32Array, nullptr) \ + v(Uint32Array, nullptr) \ + v(Float32Array, nullptr) \ + v(Float64Array, nullptr) \ + v(BigInt64Array, nullptr) \ + v(BigUint64Array, nullptr) \ #define DECLARE_LINK_TIME_CONSTANT(name, code) name, diff --git a/Source/JavaScriptCore/runtime/JSGlobalObject.cpp b/Source/JavaScriptCore/runtime/JSGlobalObject.cpp index eaef13451cf41..d75c5fc6dc988 100644 --- a/Source/JavaScriptCore/runtime/JSGlobalObject.cpp +++ b/Source/JavaScriptCore/runtime/JSGlobalObject.cpp @@ -879,7 +879,9 @@ void JSGlobalObject::init(VM& vm) init.setPrototype(JS ## type ## ArrayPrototype::create(init.vm, init.global, JS ## type ## ArrayPrototype::createStructure(init.vm, init.global, init.global->m_typedArrayProto.get(init.global)))); \ init.setStructure(JS ## type ## Array::createStructure(init.vm, init.global, init.prototype)); \ init.setConstructor(JS ## type ## ArrayConstructor::create(init.vm, init.global, JS ## type ## ArrayConstructor::createStructure(init.vm, init.global, init.global->m_typedArraySuperConstructor.get(init.global)), init.prototype, #type "Array"_s)); \ - init.global->putDirect(init.vm, init.vm.propertyNames->builtinNames().type ## ArrayPrivateName(), init.constructor, static_cast(PropertyAttribute::DontEnum)); \ + }); \ + m_linkTimeConstants[static_cast(LinkTimeConstant::type##Array)].initLater([](const Initializer& init) { \ + init.set(jsCast(init.owner)->typedArrayConstructor(TypedArrayType::Type##type)); \ }); FOR_EACH_TYPED_ARRAY_TYPE_EXCLUDING_DATA_VIEW(INIT_TYPED_ARRAY_LATER) #undef INIT_TYPED_ARRAY_LATER