Bug 1884150 - Ship growable and resizeable ArrayBuffers; r=sfink

Differential Revision: https://phabricator.services.mozilla.com/D210708
This commit is contained in:
Daniel Minor 2024-05-28 21:06:18 +00:00
parent 2d50173da7
commit a025ae7f58
5 changed files with 23 additions and 45 deletions

View File

@ -12498,11 +12498,11 @@ bool SetGlobalOptionsPreJSInit(const OptionParser& op) {
if (op.getBoolOption("disable-well-formed-unicode-strings")) {
JS::Prefs::setAtStartup_well_formed_unicode_strings(false);
}
#ifdef NIGHTLY_BUILD
if (op.getBoolOption("enable-arraybuffer-resizable")) {
JS::Prefs::setAtStartup_experimental_arraybuffer_resizable(true);
JS::Prefs::setAtStartup_experimental_sharedarraybuffer_growable(true);
}
#ifdef NIGHTLY_BUILD
if (op.getBoolOption("enable-iterator-helpers")) {
JS::Prefs::setAtStartup_experimental_iterator_helpers(true);
}

View File

@ -350,9 +350,7 @@ static const JSPropertySpec arraybuffer_properties[] = {
static const JSFunctionSpec arraybuffer_proto_functions[] = {
JS_SELF_HOSTED_FN("slice", "ArrayBufferSlice", 2, 0),
#ifdef NIGHTLY_BUILD
JS_FN("resize", ArrayBufferObject::resize, 1, 0),
#endif
JS_FN("transfer", ArrayBufferObject::transfer, 0, 0),
JS_FN("transferToFixedLength", ArrayBufferObject::transferToFixedLength, 0,
0),
@ -361,10 +359,8 @@ static const JSFunctionSpec arraybuffer_proto_functions[] = {
static const JSPropertySpec arraybuffer_proto_properties[] = {
JS_PSG("byteLength", ArrayBufferObject::byteLengthGetter, 0),
#ifdef NIGHTLY_BUILD
JS_PSG("maxByteLength", ArrayBufferObject::maxByteLengthGetter, 0),
JS_PSG("resizable", ArrayBufferObject::resizableGetter, 0),
#endif
JS_PSG("detached", ArrayBufferObject::detachedGetter, 0),
JS_STRING_SYM_PS(toStringTag, "ArrayBuffer", JSPROP_READONLY),
JS_PS_END,
@ -428,11 +424,9 @@ static bool IsArrayBuffer(HandleValue v) {
return v.isObject() && v.toObject().is<ArrayBufferObject>();
}
#ifdef NIGHTLY_BUILD
static bool IsResizableArrayBuffer(HandleValue v) {
return v.isObject() && v.toObject().is<ResizableArrayBufferObject>();
}
#endif
MOZ_ALWAYS_INLINE bool ArrayBufferObject::byteLengthGetterImpl(
JSContext* cx, const CallArgs& args) {
@ -524,7 +518,6 @@ static ArrayBufferObject* ArrayBufferCopyAndDetach(
arrayBuffer);
}
#ifdef NIGHTLY_BUILD
/**
* get ArrayBuffer.prototype.maxByteLength
*
@ -583,7 +576,6 @@ bool ArrayBufferObject::resizableGetter(JSContext* cx, unsigned argc,
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsArrayBuffer, resizableGetterImpl>(cx, args);
}
#endif
/**
* get ArrayBuffer.prototype.detached
@ -677,7 +669,6 @@ bool ArrayBufferObject::transferToFixedLength(JSContext* cx, unsigned argc,
args);
}
#ifdef NIGHTLY_BUILD
/**
* ArrayBuffer.prototype.resize ( newLength )
*
@ -732,7 +723,6 @@ bool ArrayBufferObject::resize(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsResizableArrayBuffer, resizeImpl>(cx, args);
}
#endif
/*
* ArrayBuffer.isView(obj); ES6 (Dec 2013 draft) 24.1.3.1
@ -763,7 +753,6 @@ bool ArrayBufferObject::class_constructor(JSContext* cx, unsigned argc,
// Step 3.
mozilla::Maybe<uint64_t> maxByteLength;
#ifdef NIGHTLY_BUILD
if (JS::Prefs::experimental_arraybuffer_resizable()) {
// Inline call to GetArrayBufferMaxByteLengthOption.
if (args.get(1).isObject()) {
@ -790,7 +779,6 @@ bool ArrayBufferObject::class_constructor(JSContext* cx, unsigned argc,
}
}
}
#endif
// Step 4 (Inlined 25.1.3.1 AllocateArrayBuffer).
// 25.1.3.1, step 4 (Inlined 10.1.13 OrdinaryCreateFromConstructor, step 2).

View File

@ -2215,14 +2215,6 @@ JS_PUBLIC_API bool js::ShouldIgnorePropertyDefinition(JSContext* cx,
return true;
}
#ifdef NIGHTLY_BUILD
if (key == JSProto_ArrayBuffer && !JS::Prefs::arraybuffer_transfer() &&
(id == NameToId(cx->names().transfer) ||
id == NameToId(cx->names().transferToFixedLength) ||
id == NameToId(cx->names().detached))) {
return true;
}
if (key == JSProto_ArrayBuffer &&
!JS::Prefs::experimental_arraybuffer_resizable() &&
(id == NameToId(cx->names().maxByteLength) ||
@ -2239,6 +2231,14 @@ JS_PUBLIC_API bool js::ShouldIgnorePropertyDefinition(JSContext* cx,
return true;
}
if (key == JSProto_ArrayBuffer && !JS::Prefs::arraybuffer_transfer() &&
(id == NameToId(cx->names().transfer) ||
id == NameToId(cx->names().transferToFixedLength) ||
id == NameToId(cx->names().detached))) {
return true;
}
#ifdef NIGHTLY_BUILD
if (key == JSProto_Uint8Array &&
!JS::Prefs::experimental_uint8array_base64() &&
(id == NameToId(cx->names().setFromBase64) ||

View File

@ -321,11 +321,9 @@ static bool IsSharedArrayBuffer(HandleValue v) {
return v.isObject() && v.toObject().is<SharedArrayBufferObject>();
}
#ifdef NIGHTLY_BUILD
static bool IsGrowableSharedArrayBuffer(HandleValue v) {
return v.isObject() && v.toObject().is<GrowableSharedArrayBufferObject>();
}
#endif
MOZ_ALWAYS_INLINE bool SharedArrayBufferObject::byteLengthGetterImpl(
JSContext* cx, const CallArgs& args) {
@ -342,7 +340,6 @@ bool SharedArrayBufferObject::byteLengthGetter(JSContext* cx, unsigned argc,
args);
}
#ifdef NIGHTLY_BUILD
/**
* get SharedArrayBuffer.prototype.maxByteLength
*/
@ -429,7 +426,6 @@ bool SharedArrayBufferObject::grow(JSContext* cx, unsigned argc, Value* vp) {
CallArgs args = CallArgsFromVp(argc, vp);
return CallNonGenericMethod<IsGrowableSharedArrayBuffer, growImpl>(cx, args);
}
#endif
// ES2024 draft rev 3a773fc9fae58be023228b13dbbd402ac18eeb6b
// 25.2.3.1 SharedArrayBuffer ( length [ , options ] )
@ -450,7 +446,6 @@ bool SharedArrayBufferObject::class_constructor(JSContext* cx, unsigned argc,
// Step 3.
mozilla::Maybe<uint64_t> maxByteLength;
#ifdef NIGHTLY_BUILD
if (JS::Prefs::experimental_sharedarraybuffer_growable()) {
// Inline call to GetArrayBufferMaxByteLengthOption.
if (args.get(1).isObject()) {
@ -477,7 +472,6 @@ bool SharedArrayBufferObject::class_constructor(JSContext* cx, unsigned argc,
}
}
}
#endif
// Step 4 (Inlined 25.2.2.1 AllocateSharedArrayBuffer).
// 25.2.2.1, step 5 (Inlined 10.1.13 OrdinaryCreateFromConstructor, step 2).
@ -747,18 +741,14 @@ static const JSPropertySpec sharedarray_properties[] = {
static const JSFunctionSpec sharedarray_proto_functions[] = {
JS_SELF_HOSTED_FN("slice", "SharedArrayBufferSlice", 2, 0),
#ifdef NIGHTLY_BUILD
JS_FN("grow", SharedArrayBufferObject::grow, 1, 0),
#endif
JS_FS_END,
};
static const JSPropertySpec sharedarray_proto_properties[] = {
JS_PSG("byteLength", SharedArrayBufferObject::byteLengthGetter, 0),
#ifdef NIGHTLY_BUILD
JS_PSG("maxByteLength", SharedArrayBufferObject::maxByteLengthGetter, 0),
JS_PSG("growable", SharedArrayBufferObject::growableGetter, 0),
#endif
JS_STRING_SYM_PS(toStringTag, "SharedArrayBuffer", JSPROP_READONLY),
JS_PS_END,
};

View File

@ -7701,6 +7701,20 @@
mirror: always
set_spidermonkey_pref: startup
# Experimental support for resizable ArrayBuffers in JavaScript.
- name: javascript.options.experimental.arraybuffer_resizable
type: bool
value: true
mirror: always
set_spidermonkey_pref: startup
# Experimental support for growable SharedArrayBuffers in JavaScript.
- name: javascript.options.experimental.sharedarraybuffer_growable
type: bool
value: true
mirror: always
set_spidermonkey_pref: startup
#ifdef NIGHTLY_BUILD
# Experimental support for Iterator Helpers in JavaScript.
- name: javascript.options.experimental.iterator_helpers
@ -7723,20 +7737,6 @@
mirror: always
set_spidermonkey_pref: startup
# Experimental support for resizable ArrayBuffers in JavaScript.
- name: javascript.options.experimental.arraybuffer_resizable
type: bool
value: false
mirror: always
set_spidermonkey_pref: startup
# Experimental support for growable SharedArrayBuffers in JavaScript.
- name: javascript.options.experimental.sharedarraybuffer_growable
type: bool
value: false
mirror: always
set_spidermonkey_pref: startup
# Experimental support for Uint8Array base64/hex in JavaScript.
- name: javascript.options.experimental.uint8array_base64
type: bool