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

add species support to typed arrays #1454

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/org/mozilla/javascript/typedarrays/NativeArrayBufferView.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdScriptableObject;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Symbol;
import org.mozilla.javascript.SymbolKey;
import org.mozilla.javascript.Undefined;

/**
Expand Down Expand Up @@ -129,6 +132,14 @@ protected int findInstanceIdInfo(String s) {
return instanceIdInfo(READONLY | PERMANENT, id);
}

@Override
public Object get(Symbol key, Scriptable start) {
if (SymbolKey.TO_STRING_TAG.equals(key)) {
return getClassName();
}
return super.get(key, start);
}

private static final int Id_buffer = 1, Id_byteOffset = 2, Id_byteLength = 3;

// to be visible by subclasses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -39,7 +40,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeFloat32Array a = new NativeFloat32Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -39,7 +40,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeFloat64Array a = new NativeFloat64Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/org/mozilla/javascript/typedarrays/NativeInt16Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -38,7 +39,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeInt16Array a = new NativeInt16Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/org/mozilla/javascript/typedarrays/NativeInt32Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntime;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -39,7 +40,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeInt32Array a = new NativeInt32Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/org/mozilla/javascript/typedarrays/NativeInt8Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -37,7 +38,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeInt8Array a = new NativeInt8Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -38,7 +39,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeUint16Array a = new NativeUint16Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -38,7 +39,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeUint32Array a = new NativeUint32Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion src/org/mozilla/javascript/typedarrays/NativeUint8Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -37,7 +38,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeUint8Array a = new NativeUint8Array();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import org.mozilla.javascript.Context;
import org.mozilla.javascript.IdFunctionObject;
import org.mozilla.javascript.ScriptRuntimeES6;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.Undefined;

Expand Down Expand Up @@ -39,7 +40,8 @@ public String getClassName() {

public static void init(Context cx, Scriptable scope, boolean sealed) {
NativeUint8ClampedArray a = new NativeUint8ClampedArray();
a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
IdFunctionObject constructor = a.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed);
ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);
}

@Override
Expand Down
22 changes: 22 additions & 0 deletions testsrc/jstests/es6/dataview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = DataView[Symbol.species];
assertEquals(undefined, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var ab = new ArrayBuffer(256);
var d = new DataView(ab, 1, 255);;

assertEquals('DataView', d[Symbol.toStringTag]);
assertEquals(false, d.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, DataView.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, DataView.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/float32array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Float32Array[Symbol.species];
assertEquals(Float32Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Float32Array(4);
assertEquals('Float32Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Float32Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Float32Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/float64array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Float64Array[Symbol.species];
assertEquals(Float64Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Float64Array(4);
assertEquals('Float64Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Float64Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Float64Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/int16array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Int16Array[Symbol.species];
assertEquals(Int16Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Int16Array(4);
assertEquals('Int16Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Int16Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Int16Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/int32array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Int32Array[Symbol.species];
assertEquals(Int32Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Int32Array(4);
assertEquals('Int32Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Int32Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Int32Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/int8array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Int8Array[Symbol.species];
assertEquals(Int8Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Int8Array(4);
assertEquals('Int8Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Int8Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Int8Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/uint16array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint16Array[Symbol.species];
assertEquals(Uint16Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Uint16Array(4);
assertEquals('Uint16Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint16Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint16Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/uint32array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint32Array[Symbol.species];
assertEquals(Uint32Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Uint32Array(4);
assertEquals('Uint32Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint32Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint32Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/uint8array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint8Array[Symbol.species];
assertEquals(Uint8Array, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Uint8Array(4);
assertEquals('Uint8Array', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint8Array.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint8Array.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
20 changes: 20 additions & 0 deletions testsrc/jstests/es6/uint8clampedarray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint8ClampedArray[Symbol.species];
assertEquals(Uint8ClampedArray, symbolSpeciesValue);
})();

(function TestSymbolToString() {
var a = new Uint8ClampedArray(4);
assertEquals('Uint8ClampedArray', a[Symbol.toStringTag]);
assertEquals(false, a.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint8ClampedArray.hasOwnProperty(Symbol.toStringTag));
assertEquals(false, Uint8ClampedArray.prototype.hasOwnProperty(Symbol.toStringTag));
})();

"success";
Loading
Loading