Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
camnwalter committed Oct 26, 2024
1 parent 9693b7a commit f32648b
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 110 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ private static NativeArrayBuffer js_slice(
(end < 0 ? self.getLength() + end : end))));
int startI =
ScriptRuntime.toInt32(
Math.min(
endI, Math.max(0, (start < 0 ? self.getLength() + start : start))));
Math.min(endI, Math.max(0, (start < 0 ? self.getLength() + start : start))));
int len = endI - startI;

Constructable constructor =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeFloat32Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
null,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeFloat64Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
null,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeInt16Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
null,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeInt32Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
null,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
lcx, lscope, args, NativeInt8Array::new, 1));
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeInt8Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> 1,
null,
DONTENUM | READONLY | PERMANENT);
constructor.defineProperty("BYTES_PER_ELEMENT", 1, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> 1,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", 1, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,30 +376,8 @@ static void init(
scope,
"set",
0,
(Context lcx, Scriptable lscope, Scriptable thisObj, Object[] args) -> {
NativeTypedArrayView<?> self = realThis.realThis(thisObj);
if (args.length > 0) {
if (args[0] instanceof NativeTypedArrayView) {
int offset = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : 0;
NativeTypedArrayView<?> nativeView = (NativeTypedArrayView<?>) args[0];
self.setRange(nativeView, offset);
return Undefined.instance;
}
if (args[0] instanceof NativeArray) {
int offset = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : 0;
self.setRange((NativeArray) args[0], offset);
return Undefined.instance;
}
if (args[0] instanceof Scriptable) {
// Tests show that we need to ignore a non-array object
return Undefined.instance;
}
if (isArg(args, 2)) {
return self.js_set(ScriptRuntime.toInt32(args[0]), args[1]);
}
}
throw ScriptRuntime.constructError("Error", "invalid arguments");
},
(Context lcx, Scriptable lscope, Scriptable thisObj, Object[] args) ->
js_set(lcx, lscope, thisObj, args, realThis),
DONTENUM,
DONTENUM | READONLY);
constructor.definePrototypeMethod(
Expand Down Expand Up @@ -1004,6 +982,32 @@ private static Object js_copyWithin(
return self;
}

private static Object js_set(
Context cx, Scriptable scope, Scriptable thisObj, Object[] args, RealThis realThis) {
NativeTypedArrayView<?> self = realThis.realThis(thisObj);
if (args.length > 0) {
if (args[0] instanceof NativeTypedArrayView) {
int offset = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : 0;
NativeTypedArrayView<?> nativeView = (NativeTypedArrayView<?>) args[0];
self.setRange(nativeView, offset);
return Undefined.instance;
}
if (args[0] instanceof NativeArray) {
int offset = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : 0;
self.setRange((NativeArray) args[0], offset);
return Undefined.instance;
}
if (args[0] instanceof Scriptable) {
// Tests show that we need to ignore a non-array object
return Undefined.instance;
}
if (isArg(args, 2)) {
return self.js_set(ScriptRuntime.toInt32(args[0]), args[1]);
}
}
throw ScriptRuntime.constructError("Error", "invalid arguments");
}

private static Object js_subarray(
Context cx, Scriptable scope, Scriptable thisObj, Object[] args, RealThis realThis) {
NativeTypedArrayView<?> self = realThis.realThis(thisObj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeUint16Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
null,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeUint32Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
null,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> BYTES_PER_ELEMENT,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", BYTES_PER_ELEMENT, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
lcx, lscope, args, NativeUint8Array::new, 1));
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeUint8Array::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> 1,
null,
DONTENUM | READONLY | PERMANENT);
constructor.defineProperty("BYTES_PER_ELEMENT", 1, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> 1,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", 1, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,9 @@ public static void init(Context cx, Scriptable scope, boolean sealed) {
lcx, lscope, args, NativeUint8ClampedArray::new, 1));
constructor.setPrototypePropertyAttributes(DONTENUM | READONLY | PERMANENT);
NativeTypedArrayView.init(cx, scope, constructor, NativeUint8ClampedArray::realThis);
constructor.defineProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> 1,
null,
DONTENUM | READONLY | PERMANENT);
constructor.defineProperty("BYTES_PER_ELEMENT", 1, DONTENUM | READONLY | PERMANENT);
constructor.definePrototypeProperty(
cx,
"BYTES_PER_ELEMENT",
(Scriptable thisObj) -> 1,
DONTENUM | READONLY | PERMANENT);
"BYTES_PER_ELEMENT", 1, DONTENUM | READONLY | PERMANENT);

ScriptRuntimeES6.addSymbolSpecies(cx, scope, constructor);

Expand Down

0 comments on commit f32648b

Please sign in to comment.