Skip to content

Commit

Permalink
intitial support for toStringTag
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Mar 8, 2024
1 parent 720b930 commit 25ddc83
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 21 deletions.
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,7 +132,18 @@ protected int findInstanceIdInfo(String s) {
return instanceIdInfo(READONLY | PERMANENT, id);
}

private static final int Id_buffer = 1, Id_byteOffset = 2, Id_byteLength = 3;
@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
protected static final int MAX_INSTANCE_ID = Id_byteLength;
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/float32array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Float32Array[Symbol.species];
assertEquals(Float32Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/float64array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Float64Array[Symbol.species];
assertEquals(Float64Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/int16array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Int16Array[Symbol.species];
assertEquals(Int16Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/int32array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Int32Array[Symbol.species];
assertEquals(Int32Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/int8array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Int8Array[Symbol.species];
assertEquals(Int8Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/uint16array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint16Array[Symbol.species];
assertEquals(Uint16Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/uint32array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint32Array[Symbol.species];
assertEquals(Uint32Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/uint8array.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint8Array[Symbol.species];
assertEquals(Uint8Array, symbolSpeciesValue);
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";
12 changes: 10 additions & 2 deletions testsrc/jstests/es6/uint8clampedarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
load("testsrc/assert.js");

(function TestSymbolSpecies() {
var symbolSpeciesValue = Uint8ClampedArray[Symbol.species];
assertEquals(Uint8ClampedArray, symbolSpeciesValue);
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";
14 changes: 14 additions & 0 deletions testsrc/org/mozilla/javascript/tests/es6/NativeDataViewTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* 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/. */

package org.mozilla.javascript.tests.es6;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.drivers.LanguageVersion;
import org.mozilla.javascript.drivers.RhinoTest;
import org.mozilla.javascript.drivers.ScriptTestsBase;

@RhinoTest("testsrc/jstests/es6/dataview.js")
@LanguageVersion(Context.VERSION_ES6)
public class NativeDataViewTest extends ScriptTestsBase {}
11 changes: 9 additions & 2 deletions testsrc/test262.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1643,7 +1643,7 @@ built-ins/ThrowTypeError 7/13 (53.85%)
unique-per-realm-non-simple.js
unique-per-realm-unmapped-args.js

built-ins/TypedArray 979/1070 (91.5%)
built-ins/TypedArray 978/1070 (91.4%)
from/arylk-get-length-error.js
from/arylk-to-length-error.js
from/iter-access-error.js
Expand Down Expand Up @@ -2160,7 +2160,14 @@ built-ins/TypedArray 979/1070 (91.5%)
prototype/subarray/this-is-not-object.js
prototype/subarray/this-is-not-typedarray-instance.js
prototype/Symbol.toStringTag/BigInt 9/9 (100.0%)
prototype/Symbol.toStringTag 9/9 (100.0%)
prototype/Symbol.toStringTag/detached-buffer.js
prototype/Symbol.toStringTag/invoked-as-accessor.js
prototype/Symbol.toStringTag/invoked-as-func.js
prototype/Symbol.toStringTag/length.js
prototype/Symbol.toStringTag/name.js
prototype/Symbol.toStringTag/prop-desc.js
prototype/Symbol.toStringTag/this-has-no-typedarrayname-internal.js
prototype/Symbol.toStringTag/this-is-not-object.js
prototype/toLocaleString/BigInt 13/13 (100.0%)
prototype/toLocaleString/calls-tolocalestring-from-each-value.js
prototype/toLocaleString/calls-tostring-from-each-value.js
Expand Down

0 comments on commit 25ddc83

Please sign in to comment.