RESOLVED FIXED219527
Align %TypedArray% constructor behavior with spec
https://bugs.webkit.org/show_bug.cgi?id=219527
Summary Align %TypedArray% constructor behavior with spec
Ross Kirsling
Reported 2020-12-03 19:25:56 PST
Align %TypedArray% constructor behavior with spec
Attachments
Patch (16.14 KB, patch)
2020-12-03 19:47 PST, Ross Kirsling
no flags
Patch (17.76 KB, patch)
2020-12-03 23:06 PST, Ross Kirsling
no flags
Patch (21.83 KB, patch)
2020-12-07 15:29 PST, Ross Kirsling
no flags
Patch for landing (32.34 KB, patch)
2020-12-08 12:17 PST, Ross Kirsling
no flags
Ross Kirsling
Comment 1 2020-12-03 19:47:56 PST
Ross Kirsling
Comment 2 2020-12-03 23:06:08 PST
Ross Kirsling
Comment 3 2020-12-03 23:13:20 PST
Comment on attachment 415391 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=415391&action=review > Source/JavaScriptCore/ChangeLog:21 > + 3. Typed array argument (https://tc39.es/ecma262/#sec-initializetypedarrayfromtypedarray): > + We need to support the case where the input typed array uses a custom ArrayBuffer. > + This case is *extremely* strange -- we still create the same type of typed array with a normal ArrayBuffer, > + but we override the prototype of that ArrayBuffer to input.buffer.constructor[@@species].prototype. Note: There appears to be interest in removing @@species for ArrayBuffers, so it might be useful to have JSC continue to fail these tests as "web compatibility insurance". In that case, we could split (3) out from the rest.
Ross Kirsling
Comment 4 2020-12-04 13:02:08 PST
Oops, I forgot that the relevant proposal about the @@species removal is https://github.com/tc39/proposal-rm-builtin-subclassing. But it sounds like folks would like to remove @@species from ArrayBuffers even if web compat issues were discovered for other classes.
Yusuke Suzuki
Comment 5 2020-12-04 13:52:10 PST
Comment on attachment 415391 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=415391&action=review Looks good! But I think we should have species optimization at the first patch since new TypedArray(arrayBuffer) is common enough. > Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructorInlines.h:115 > + JSValue constructor = source->get(globalObject, vm.propertyNames->constructor); Let's avoid doing property access by having watchpoint like Array / ArrayBuffer are doing since `new TypedArray(arrayBuffer)` is enough critical path. See speciesConstructArrayBuffer and speciesConstructArray.
Yusuke Suzuki
Comment 6 2020-12-04 13:53:54 PST
Comment on attachment 415391 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=415391&action=review >> Source/JavaScriptCore/runtime/JSGenericTypedArrayViewConstructorInlines.h:115 >> + JSValue constructor = source->get(globalObject, vm.propertyNames->constructor); > > Let's avoid doing property access by having watchpoint like Array / ArrayBuffer are doing since `new TypedArray(arrayBuffer)` is enough critical path. > See speciesConstructArrayBuffer and speciesConstructArray. Possibly I think modifying speciesConstructArrayBuffer and reusing it would be possible.
Ross Kirsling
Comment 7 2020-12-07 15:29:22 PST
Yusuke Suzuki
Comment 8 2020-12-07 21:36:18 PST
Comment on attachment 415594 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=415594&action=review Nice, r=me > Source/JavaScriptCore/runtime/JSArrayBufferPrototype.cpp:68 > + VM& vm = globalObject->vm(); > + auto scope = DECLARE_THROW_SCOPE(vm); > + > + bool isValid = speciesWatchpointIsValid(vm, thisObject, mode); > + scope.assertNoException(); > + if (LIKELY(isValid)) > + return WTF::nullopt; > + Can you make this part inlined when the caller is calling this? (like, definition it in JSArrayBufferPrototypeInlines.h) I think 99.9999999% of path will go to this "watchpoint is valid" case. So it is worth inlining.
Ross Kirsling
Comment 9 2020-12-08 12:17:09 PST
Created attachment 415661 [details] Patch for landing
EWS
Comment 10 2020-12-08 13:03:14 PST
Committed r270552: <https://trac.webkit.org/changeset/270552> All reviewed patches have been landed. Closing bug and clearing flags on attachment 415661 [details].
Radar WebKit Bug Importer
Comment 11 2020-12-08 13:04:15 PST
Note You need to log in before you can comment on or make changes to this bug.