Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define ArrayBufferView and TypedArray as interfaces rather than classes #4181

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

niloc132
Copy link
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/

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.
@gkdn
Copy link
Member

gkdn commented Jul 25, 2024

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

externs/es6.js Outdated Show resolved Hide resolved
@@ -1140,7 +1142,7 @@ BigUint64Array.of = function(var_args) {};
* @param {number=} opt_byteOffset
* @param {number=} opt_byteLength
* @constructor
* @extends {ArrayBufferView}
* @implements {ArrayBufferView}
* @throws {Error}
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays/DataView
*/
Copy link
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
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
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
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
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
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
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

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.

5 participants