Skip to content

Define ArrayBufferView and TypedArray as interfaces rather than classes#4181

Open
niloc132 wants to merge 8 commits intogoogle:masterfrom
Vertispan:typedarray-arraybufferview-interfaces
Open

Define ArrayBufferView and TypedArray as interfaces rather than classes#4181
niloc132 wants to merge 8 commits intogoogle:masterfrom
Vertispan:typedarray-arraybufferview-interfaces

Conversation

@niloc132
Copy link
Copy Markdown
Contributor

Technically, the former appears to be a typedef and the latter might be a template for classes? But neither exists as a named function/constructor. Earlier versions of the spec do indicate that both were at one point interfaces though.

This impacts https://github.com/google/elemental2, which then tries to use both types on the right side of JS instanceof operations, which will fail ("Right-hand side of 'instanceof' is not an object").

As an alternative, one or both could be a typedef as the second link below seems to say? The archive.org link shows the older version where both were defined as interfaces.

https://tc39.es/ecma262/multipage/ordinary-and-exotic-objects-behaviours.html#typedarray
https://webidl.spec.whatwg.org/#ArrayBufferView
http://web.archive.org/web/20150108144329/https://www.khronos.org/registry/typedarray/specs/latest/

@gkdn
Copy link
Copy Markdown
Member

gkdn commented Jul 25, 2024

@mollyibot Could you patch the PR internally and see if it causes any problems?

* @implements {ArrayBufferView}
* @throws {Error}
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays/DataView
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and this breaks j2clproto and elemental2 tests, taking a deeper look.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at first , tests failed No name provided for parameter 'elemental2.core.ReadonlyArray.EveryCallbackFn.onInvoke.p0'. Name can be specified in a name mapping file. after removing some unused integer entities from elemental2, this error went away. Then tests failed //third_party/java_src/j2cl_proto/java/com/google/protobuf/contrib/j2cl/runtime:runtime Error:ByteString.java:78: Cannot cast from BigUint64Array to Uint8Array , and also

Exception in thread "main" java.lang.IllegalStateException: No declaration found for member [Property {  name: BYTES_PER_ELEMENT, type:number, inferred: false}]. Please fix the extern file. A class must implement all methods from its super interfaces.

and

Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.at(int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.subarray(int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.slice(int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.toString_()
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:BigInt64Array.java:22: The type BigInt64Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:BigInt64Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:BigInt64Array.java:186: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:BigInt64Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:BigInt64Array.java:190: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:BigInt64Array.java:206: The return type is incompatible with TypedArray.indexOf(double)
Error:BigInt64Array.java:211: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.at(int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.subarray(int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.slice(int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.toString_()
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:BigUint64Array.java:21: The type BigUint64Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:BigUint64Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:BigUint64Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:BigUint64Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:BigUint64Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:BigUint64Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:BigUint64Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.at(int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.slice(int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.toString_()
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Float32Array.java:21: The type Float32Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Float32Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Float32Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Float32Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Float32Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Float32Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Float32Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.at(int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.slice(int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.toString_()
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Float64Array.java:21: The type Float64Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Float64Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Float64Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Float64Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Float64Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Float64Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Float64Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.at(int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.slice(int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.toString_()
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Int16Array.java:21: The type Int16Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Int16Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Int16Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Int16Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Int16Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Int16Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Int16Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.at(int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.slice(int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.toString_()
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Int32Array.java:21: The type Int32Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Int32Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Int32Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Int32Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Int32Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Int32Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Int32Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.at(int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.slice(int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.toString_()
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Int8Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Int8Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Int8Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Int8Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Int8Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Int8Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:TypedArray.java:157: The return type is incompatible with JsArrayLike<Double>.getLength()
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.at(int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.slice(int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.toString_()
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Uint16Array.java:21: The type Uint16Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Uint16Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Uint16Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Uint16Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Uint16Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Uint16Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Uint16Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.at(int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.slice(int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.toString_()
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Uint32Array.java:21: The type Uint32Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Uint32Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Uint32Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Uint32Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Uint32Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Uint32Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Uint32Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.at(int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.slice(int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.toString_()
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Uint8Array.java:21: The type Uint8Array must implement the inherited abstract method TypedArray.toLocaleString()
Error:Uint8Array.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Uint8Array.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Uint8Array.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Uint8Array.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Uint8Array.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Uint8Array.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.at(int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.subarray(int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.fill(double, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.slice(int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.slice(int, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.toString_()
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.includes(double, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Uint8ClampedArray.java:21: The type Uint8ClampedArray must implement the inherited abstract method TypedArray.toLocaleString()
Error:Uint8ClampedArray.java:184: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn, S)
Error:Uint8ClampedArray.java:185: The return type is incompatible with TypedArray.findIndex(TypedArray.FindIndexCallbackFn)
Error:Uint8ClampedArray.java:188: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn, S)
Error:Uint8ClampedArray.java:189: The return type is incompatible with TypedArray.findLastIndex(TypedArray.FindLastIndexCallbackFn)
Error:Uint8ClampedArray.java:205: The return type is incompatible with TypedArray.indexOf(double)
Error:Uint8ClampedArray.java:210: The return type is incompatible with TypedArray.lastIndexOf(double)```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking quickly at the integer_entities (for some related work, to be submitted as a PR soon), I suspect we just need to duplicate the entities found in TypedArray, as it will now be an interface, and classes that implement it now must declare the same signature, rather than just inheriting the native impl.

As an example, for these Uint8Array enjtries:

Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.copyWithin(int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.copyWithin(int, int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.at(int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.subarray(int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.subarray(int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.fill(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.fill(double, int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.slice(int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.slice(int, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.toString_()
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.indexOf(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.includes(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.lastIndexOf(double, int)
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.toLocaleString()

I think the following integer entities, will resolve most of the above (sorted by the order of the errors above they will resolve, not alphabetical as expected):

elemental2.core.Uint8Array.copyWithin.target
elemental2.core.Uint8Array.copyWithin.start
elemental2.core.Uint8Array.copyWithin.end
elemental2.core.Uint8Array.set.offset
elemental2.core.Uint8Array.at.index
elemental2.core.Uint8Array.subarray.begin
elemental2.core.Uint8Array.subarray.end
elemental2.core.Uint8Array.fill.begin
elemental2.core.Uint8Array.fill.end
elemental2.core.Uint8Array.slice.begin
elemental2.core.Uint8Array.slice.end
elemental2.core.Uint8Array.indexOf
elemental2.core.Uint8Array.indexOf.fromIndex
elemental2.core.Uint8Array.includes.fromIndex
elemental2.core.Uint8Array.lastIndexOf
elemental2.core.Uint8Array.lastIndexOf.fromIndex

This leaves the following, which I don't yet understand:

Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.toString_()
Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.toLocaleString()

and this, which I'm not certain will be resolved (but might be, if the union type is inherited correctly):

Error:Int8Array.java:21: The type Int8Array must implement the inherited abstract method TypedArray.set(TypedArray.SetArrayUnionType, int)

@gkdn
Copy link
Copy Markdown
Member

gkdn commented Jul 26, 2024

@jDramaix Could you first provide general feedback on the direction before asking Colin to invest more time adapting the solution?

@niloc132
Copy link
Copy Markdown
Contributor Author

I apologize for the churn, and am happy to spend some time exploring to make this work.

The issue I'm seeking to resolve is that when jsinterop-generator builds elemental2, it sees these types and emits classes for them rather than interfaces, and so when a typedarray of some kind is used generically, the compiler emits casts, and those will fail since there is no constructor called TypedArray or ArrayBufferView in the global context.

Note that there is a constructor called TypedArray, so it is not fully accurate to call this an interface:

> (new Uint8Array()).__proto__.__proto__.constructor 
< function TypedArray()

However, this is not accessible on the "global this", so cannot be used when performing instanceof checks. In theory GWT/J2CL could make the call above to find it, but that seems like more trouble than it would be worth?

Please let me know if there's another straightforward direction I can pursue here. I did not start trying to build elemental2 yet from this change, imagining incorrectly that it would just change the inheritance structure to the desired format. I can take a closer in a week or two, and hold off on this change for now, or if you see a fruitful direction for me to try I would be happy to follow that?

--

At a glance, I'm not clear how to override the closure-compiler repo used by elemental2 - I followed the steps provided, but my changes to closure-compiler don't seem to be reflected in the generated output (both in that I still see public class Float64Array extends TypedArray, and I don't see the failures @mollyibot mentioned above). Given that closure-compiler is now a bazel project, it looks like I want something more like

local_repository(
    name = "com_google_javascript_closure_compiler",
    path = "/home/colin/workspace/closure-compiler",
#    build_file = "jscomp.BUILD",
)

but that doesn't quite get it right - it looks like transitive dependencies from closure aren't picked up this way (@google_bazel_common, @com_github_johnynek_bazel_jar_jar, etc), and inlining most of closure's WORKSPACE then results in other issues...

@jDramaix
Copy link
Copy Markdown
Member

I agree that defining TypedArray and ArrayBufferView as interfaces is the correct approach. This aligns with how they're defined in JavaScript.

To have this change compiling successfully, we need to modify several things:

  • Changing to interfaces requires that all child classes (e.g., Int8Array, Uint8Array, etc.) explicitly redefine the methods from TypedArray and ArrayBufferView in the extern files.
  • The lines related to TypedArray and ArrayBufferView in integer_entity.txt will need to be duplicated for each child type. (This could be simplified on the JsInterop-generator side @mollyibot)
  • TypedArray redefines the length property of the IArrayLike parent interface. It was not an issue before when TypedArray was a class. But now it's an interface, JsInterop generator, will generates a JsProperty method that will conflict with the JsOverlay method present on JsArrayLike interface (type defined in jsinterop-base to represent IArrayLike)

Note that this change is likely to be a breaking change internally, so it may require some time before merging it.

@jDramaix
Copy link
Copy Markdown
Member

At a glance, I'm not clear how to override the closure-compiler repo used by elemental2 -

We used the extern files coming the closure compiler jar embedded in rules_closure We expect to have a @com_google_javascript_closure_compiler//:externs target representing a zip file containing all the extern files.
You should be able to override that at the end of the WORKSPACE file

Technically, the former appears to be a typedef and the latter might be
a template for classes? But neither exists as a named
function/constructor. Earlier versions of the spec do indicate that both
were at one point interfaces though.
@niloc132 niloc132 force-pushed the typedarray-arraybufferview-interfaces branch from e4f1e02 to 91829e4 Compare January 2, 2026 17:54
@niloc132
Copy link
Copy Markdown
Contributor Author

niloc132 commented Jan 2, 2026

Updated to latest, hoping someone can take a look at this in the new year.

@gkdn
Copy link
Copy Markdown
Member

gkdn commented Jan 6, 2026

@lauraharker does this look reasonable to you?

@niloc132
Copy link
Copy Markdown
Contributor Author

Anything else I can do to help with this PR?

@lauraharker lauraharker self-assigned this Feb 27, 2026
@lauraharker
Copy link
Copy Markdown
Contributor

I’ll try pulling in this PR and see if we run into any non-elemental2 / jsinterop issues

@gkdn
Copy link
Copy Markdown
Member

gkdn commented Mar 3, 2026

@niloc132 Do you have the corresponding elemental2 changes ready for this PR? Otherwise PR immediately hits issue with elemental that breaks further testing.

@niloc132
Copy link
Copy Markdown
Contributor Author

niloc132 commented Mar 3, 2026

No, I had understood from Julien's statement from 2024

To have this change compiling successfully, we need to modify several things:

that this was pending work to be done within Google.

For those repos it is my experience that Googlers usually wish to make their own changes, so I mostly wait and see.

google/elemental2#183
google/jsinterop-generator#48 (comment)

Like j2cl, those repos are somewhat read-only to the public - it isn't clear that I can contribute in a meaningful way.

If I'm mistaken, then I apologize and will pursue those changes as soon as I'm able.

@gkdn
Copy link
Copy Markdown
Member

gkdn commented Mar 3, 2026

We received/accepted bunch of patches to J2CL when done properly but I don't want to get into argument on this again.

@jDramaix what would you like to do about related change on on elemental2 side?

@jDramaix
Copy link
Copy Markdown
Member

jDramaix commented Mar 5, 2026

I don't know why yet but this patch breaks the conversion of functions from the TypedArray class and subclasses that use the special THIS type parameter allowing method chaining.

The root cause is that with this change, the closure compiler returns the same TemplateType instance when we lookup for the getTypeOfThis() for all the functions of all the classes in the hierarchy using THIS; breaking our mapping (The last visited type of the hierarchy is used)

e.g:

/**
 * @param {number} target
 * @param {number} start
 * @param {number=} opt_end
 * @return {THIS}
 * @this {THIS}
 * @template THIS
 */
TypedArray.prototype.copyWithin = function(target, start, opt_end) {};

generate the following Java Code:

class TypeArray {

  public native BigUint64Array copyWithin(double target, double start);
}

instead of

class TypeArray {

  public native TypeArray copyWithin(double target, double start);
}

@lauraharker any idea what could cause this different behavior in the Closure compiler ?

@jDramaix
Copy link
Copy Markdown
Member

jDramaix commented Mar 5, 2026

Thanks to @lauraharker investigation, we identified the root cause: Now that TypedArray is an interface, all the concrete classes implementing the interface need to redefine (with @OverRide annotation) the functions of TypedArray.

@niloc132
Copy link
Copy Markdown
Contributor Author

niloc132 commented Mar 5, 2026

Thanks to @lauraharker investigation, we identified the root cause: Now that TypedArray is an interface, all the concrete classes implementing the interface need to redefine (with @OverRide annotation) the functions of TypedArray.

Closure did require that I overrode the iterator symbol for each subtype:

/** @override */
Uint8ClampedArray.prototype[Symbol.iterator] = function() {};

etc.

Should closure require that to build this change I add the other members as well? If so, should that be filed as a separate bug?

Or do I misunderstand, and this is something that jsinterop-generator should handle?

@jDramaix
Copy link
Copy Markdown
Member

jDramaix commented Mar 5, 2026

With "normal" closure code, the Javascript compiler would have rejected the code. For extern file, it is more lenient (I guess for legacy reasons) and does not complaint about that.

It's mostly only impacting Elemental2 and we had to fix several externs file in order to get correct type information and generate correct Java code.

@niloc132
Copy link
Copy Markdown
Contributor Author

niloc132 commented Mar 5, 2026

Ok, I'll copy a simple override for each of these.

@niloc132 niloc132 force-pushed the typedarray-arraybufferview-interfaces branch from e9600b7 to e8e885d Compare April 8, 2026 17:40
@niloc132
Copy link
Copy Markdown
Contributor Author

niloc132 commented Apr 8, 2026

Okay, sorry for my delay on this, 3k lines of copy-paste-edit later...

I took the functions declared on TypedArray (including the ones it already had as override) and copied them to each subtype, removing prose comments and adding @override. I replaced some instances of "TypedArray" with the specific type - the args to callbacks, the function sig itself, but left URLs alone. I also left out templates on THIS, as this was inconsistently done before (see BigUint64Array.prototype.sort vs BigUint64Array.prototype.toSorted, though both have the same @suppress?), let me know if I should take more steps there.

BigUint64Array and BigInt64Array had to be further tweaked since they already had some overrides, I tried to make the added ones fit with correct alphabetical sort.

Unfortunately I have no way to validate this work (as bazel test //:all passes both before and after this new commit), but I welcome any feedback you can offer.

@lauraharker
Copy link
Copy Markdown
Contributor

Thanks! I just pulled this into our internal repo and am waiting for test results. I'll update here once that's done.

@lauraharker
Copy link
Copy Markdown
Contributor

Hmm, from what I'm seeing, landing this would be much easier if we got rid of the TypedArray interface completely.

Or at least, if we wanted to keep the TypedArray interface, removing all the method defintions from it, so it's only useful when combined with casting to a specific typed array subtype.

There's a lot of (pre-existing) wrong method signatures for BigInt64 & BigUint64 especially, where something is typed with "number" and should be "bigint".

Does anyone have any objections to removing or nerfing the TypedArray interface?

Internally - I see we only use it in a few places, and even then, we don't really seem to call methods directly off a TypedArray.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants