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 be08ffc
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,13 @@ private static NativeArrayBuffer js_slice(
LambdaConstructor defaultConstructor,
Object[] args) {
NativeArrayBuffer self = getSelf(thisObj);
double start = isArg(args, 0) ? ScriptRuntime.toNumber(args[0]) : 0;
double end = isArg(args, 1) ? ScriptRuntime.toNumber(args[1]) : self.getLength();
int endI =
int start = isArg(args, 0) ? ScriptRuntime.toInt32(args[0]) : 0;
int end = isArg(args, 1) ? ScriptRuntime.toInt32(args[1]) : self.getLength();
end = Math.max(0, Math.min(self.getLength(), (end < 0 ? self.getLength() + end : end)));
start =
ScriptRuntime.toInt32(
Math.max(
0,
Math.min(
self.getLength(),
(end < 0 ? self.getLength() + end : end))));
int startI =
ScriptRuntime.toInt32(
Math.min(
endI, Math.max(0, (start < 0 ? self.getLength() + start : start))));
int len = endI - startI;
Math.min(end, Math.max(0, (start < 0 ? self.getLength() + start : start))));
int len = end - start;

Constructable constructor =
AbstractEcmaObjectOperations.speciesConstructor(cx, thisObj, defaultConstructor);
Expand All @@ -183,7 +176,7 @@ private static NativeArrayBuffer js_slice(
throw ScriptRuntime.typeErrorById("msg.arraybuf.smaller.len", len, actualLength);
}

System.arraycopy(self.buffer, startI, buf.buffer, 0, len);
System.arraycopy(self.buffer, start, buf.buffer, 0, len);
return buf;
}

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 be08ffc

Please sign in to comment.