Skip to content
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
2 changes: 1 addition & 1 deletion crates/perry-runtime/src/object/global_this_webassembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ fn install_webassembly_object_property(
// Unit tests (#6558). Only the non-throwing arms are exercised here — the
// `js_throw` paths longjmp and are covered by the e2e/parity fixtures
// (`test-parity/node-suite/globals/webassembly-*.ts`,
// `tests/test_webassembly_graceful_fail.sh`).
// `test-files/test_parity_webassembly_graceful_fail_default.ts`).
// ────────────────────────────────────────────────────────────────────────

#[cfg(test)]
Expand Down
12 changes: 12 additions & 0 deletions test-files/fixtures/parity_5891/chained_cross_module_getter/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class Scroll {
private _top: number = 42;
get scrollTop(): number { return this._top; }
}
export class Viewport {
readonly scroll: Scroll;
constructor() { this.scroll = new Scroll(); }
}
export class VM {
readonly viewport: Viewport;
constructor() { this.viewport = new Viewport(); }
}
5 changes: 5 additions & 0 deletions test-files/fixtures/parity_5891/cross_module_getter/lib.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class Box {
field: number = 100;
method(): number { return 200; }
get prop(): number { return 300; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as z from "./types.ts";
export { z };
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class ZS {
v = 5;
static create = (): ZS => new ZS();
}
const stringType = ZS.create;
export { stringType as string };
31 changes: 31 additions & 0 deletions test-files/fixtures/parity_5891/imported_accessor/base_texture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const LinearFilter = 1006;
export class BaseTexture {
public source: any;
public version = 0;
public magFilter: number;
public minFilter: number;
public generateMipmaps = true;
public flipY = true;
public unpackAlignment = 4;
constructor(
image: any = null, _mapping?: any, _wrapS?: any, _wrapT?: any,
magFilter: number = LinearFilter, minFilter: number = LinearFilter,
_format?: any, _type?: any, _anisotropy?: any, _colorSpace?: any,
) {
this.source = { data: image, version: 0 };
this.magFilter = magFilter;
this.minFilter = minFilter;
}
get image(): any { return this.source.data; }
set image(value: any) { this.source.data = value; }
get readOnlyTag(): string { return "base-read-only"; }
set writeOnlyTag(value: string) { this.source.writeOnlyTag = value; }
set needsUpdate(value: boolean) {
if (value === true) { this.version++; this.source.version++; }
}
}
export class AliasAccessorBase {
public marker: any = "unset";
get aliasedValue(): any { return this.marker; }
set aliasedValue(value: any) { this.marker = value; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function StripeResource(this: any, stripe: any, deprecated: any) {
if (deprecated) throw new Error("invoked with a second arg");
this._stripe = stripe;
}
(StripeResource as any).method = function () { return "M"; };
(StripeResource as any).extend = function () { return "E"; };
(StripeResource as any).MAX = 42;
(StripeResource as any).prototype = { _stripe: null, path: "", initialize() {} };
export { StripeResource };
6 changes: 6 additions & 0 deletions test-files/fixtures/parity_5891/namespace_const/util_mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export namespace util {
export function fn() { return "FN"; }
export const objectKeys = (obj: any) => Object.keys(obj);
export const arrow = () => "ARROW";
export const num = 42;
}
7 changes: 7 additions & 0 deletions test-files/fixtures/parity_5891/namespace_import/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const alpha = { id: 1 };
export const beta = { id: 2 };
export const gammaEnum = ["x", "y"] as const;
export function helper() { return "H"; }
export type Alpha = typeof alpha;
export type Beta = typeof beta;
export interface Thing { id: number }
4 changes: 4 additions & 0 deletions test-files/fixtures/parity_5891/namespace_reexport/barrel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import * as z from "./external.ts";
export * from "./external.ts";
export { z };
export default z;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./sub.ts";
export const coerce = { number: () => 42 };
1 change: 1 addition & 0 deletions test-files/fixtures/parity_5891/namespace_reexport/sub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function object() { return "obj"; }
6 changes: 6 additions & 0 deletions test-files/fixtures/parity_5891/native_class/data_texture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { TextureLike } from "./texture.ts";
export class DataTextureLike extends TextureLike {
declare readonly isDataTexture: true;
declare static readonly DEFAULT_IMAGE: unknown;
dataTag = "data-texture";
}
4 changes: 4 additions & 0 deletions test-files/fixtures/parity_5891/native_class/source.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class SourceLike {
version = 0;
set needsUpdate(value: boolean) { if (value === true) this.version++; }
}
5 changes: 5 additions & 0 deletions test-files/fixtures/parity_5891/native_class/texture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SourceLike } from "./source.ts";
export class TextureLike {
source = new SourceLike();
set needsUpdate(value: boolean) { this.source.needsUpdate = value; }
}
2 changes: 2 additions & 0 deletions test-files/fixtures/parity_5891/object_shorthand/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const db = { tag: "DBINST", q: () => 7 };
export const helper = () => "H";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const kindOf = (x: unknown): string => "data:" + typeof x;
3 changes: 3 additions & 0 deletions test-files/fixtures/parity_5891/type_only_namespace/Schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const kindOf = (_x: unknown): string => {
throw new Error("Schema.kindOf must never be reached at runtime");
};
2 changes: 2 additions & 0 deletions test-files/fixtures/parity_5891/xmod_empty/mid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { EffectfulRoot } from "./root.ts";
export class EmptyMid extends EffectfulRoot {}
3 changes: 3 additions & 0 deletions test-files/fixtures/parity_5891/xmod_empty/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class EffectfulRoot {
constructor(value: any) { (this as any).forwarded = value; }
}
13 changes: 13 additions & 0 deletions test-files/fixtures/parity_5891/xmod_multilevel/base_object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class MatrixLike {
label: string;
constructor(label: string) { this.label = label; }
decompose() { return "decompose:" + this.label; }
}
export class BaseObject {
constructor() {
Object.defineProperties(this, { hiddenMarker: { value: "hidden", configurable: true } });
(this as any).plainBase = "base";
(this as any).matrixWorld = new MatrixLike("world");
}
updateMatrixWorld(force?: boolean) { return (this as any).matrixWorld.decompose() + ":" + String(force); }
}
10 changes: 10 additions & 0 deletions test-files/fixtures/parity_5891/xmod_multilevel/camera_base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BaseObject, MatrixLike } from "./base_object.ts";
export class CameraBase extends BaseObject {
declare matrixWorld: MatrixLike;
declare matrixWorldInverse: MatrixLike;
constructor() {
super();
(this as any).matrixWorldInverse = new MatrixLike("inverse");
(this as any).cameraReady = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { CameraBase } from "./camera_base.ts";
import { MatrixLike } from "./base_object.ts";
export class PerspectiveLike extends CameraBase {
constructor(fov: number, aspect: number, near: number, far: number) {
super();
(this as any).isPerspectiveLike = true;
(this as any).projectionMatrix = new MatrixLike(`projection:${fov}:${aspect}:${near}:${far}`);
}
}
4 changes: 4 additions & 0 deletions test-files/fixtures/parity_5891/xmod_zero/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { CrossRoot } from "./root.ts";
export class CrossBase extends CrossRoot {
constructor() { super(); (this as any).baseReady = "base"; }
}
3 changes: 3 additions & 0 deletions test-files/fixtures/parity_5891/xmod_zero/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class CrossRoot {
constructor() { (this as any).rootReady = "root"; }
}
6 changes: 6 additions & 0 deletions test-files/test_parity_684_type_only_namespace_collision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { kindOf } from "./fixtures/parity_5891/type_only_namespace/Data.ts";
import type * as Schema from "./fixtures/parity_5891/type_only_namespace/Schema.ts";

console.log(kindOf(42));
console.log(kindOf("hi"));
type _Unused = ReturnType<typeof Schema.kindOf>;
11 changes: 11 additions & 0 deletions test-files/test_parity_array_property_index_set_4150.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
interface State { width: number; mirror: number[] }
function write(state: State, cell: number, value: number): void { state.mirror[cell] = value; }

const state: State = { width: 20, mirror: new Array(40) };
write(state, 0, 112);
write(state, 1, 101);
state.mirror[2] = 114;
if (state.mirror[0] !== 112 || state.mirror[1] !== 101 || state.mirror[2] !== 114) {
throw new Error(`indexed writes: ${state.mirror[0]}, ${state.mirror[1]}, ${state.mirror[2]}`);
}
console.log("array property index set ok");
29 changes: 29 additions & 0 deletions test-files/test_parity_async_gen_await_in_conditional_6728.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class EventStream {
queue: string[] = [];
resolve: (() => void) | null = null;
done = false;
push(e: string) {
this.queue.push(e);
if (this.resolve) { const resolve = this.resolve; this.resolve = null; resolve(); }
}
async *[Symbol.asyncIterator](): AsyncGenerator<string> {
while (true) {
if (this.queue.length === 0) {
if (this.done) return;
await new Promise<void>((resolve) => { this.resolve = resolve; });
}
while (this.queue.length > 0) yield this.queue.shift() as string;
}
}
}
const stream = new EventStream();
(async () => {
for await (const event of stream) {
console.log("event " + event);
if (event === "last") { console.log("got last"); process.exit(0); }
}
})();
setTimeout(() => stream.push("working"), 50);
setTimeout(() => stream.push("token"), 100);
setTimeout(() => stream.push("last"), 150);
setTimeout(() => { console.log("GUARD (deadlocked)"); process.exit(2); }, 3000);
28 changes: 28 additions & 0 deletions test-files/test_parity_async_semantic_3583.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
async function returnsValue() { return 42; }
function failDefault(): number { throw "default-boom"; }
function failArrowDefault(): number { throw "arrow-default-boom"; }
async function rejectsDefault(value = failDefault()) { console.log("default body ran"); return value; }
async function throwsNow() { throw "throw-boom"; }
async function lengthOne(a: number, b = 39) { return a + b; }
const arrowLengthOne = async (a: number, b = 39) => a + b;
const rejectsArrowDefault = async (value = failArrowDefault()) => {
console.log("arrow body ran");
return value;
};

returnsValue().then((value) => console.log("return " + value));
rejectsDefault().then(
() => console.log("default unexpectedly resolved"),
(err) => console.log("default rejected " + err),
);
throwsNow().then(
() => console.log("throw unexpectedly resolved"),
(err) => console.log("throw rejected " + err),
);
rejectsArrowDefault().then(
() => console.log("arrow default unexpectedly resolved"),
(err) => console.log("arrow default rejected " + err),
);
console.log("fn length " + lengthOne.length);
console.log("arrow length " + arrowLengthOne.length);
console.log("sync end");
33 changes: 33 additions & 0 deletions test-files/test_parity_async_try_catch_after_await_4036.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function boom() { throw "call-boom"; }
function syncCatch() {
try { throw "sync-boom"; } catch (e: any) { console.log("sync caught:", e); }
}
async function noPriorAwait() {
try { throw "no-await-boom"; } catch (e: any) { console.log("no-await caught:", e); }
}
async function directPostAwait() {
await 0;
try { throw "direct-boom"; } catch (e: any) { console.log("direct caught:", e); }
}
async function callPostAwait() {
await 0;
try { boom(); } catch (e: any) { console.log("call caught:", e); }
}
async function promiseResolvePostAwait() {
await Promise.resolve(1);
try { throw new Error("promise-boom"); } catch (e: any) { console.log("promise caught:", e.message); }
}
async function rejectedAwaitStillWorks() {
try {
await Promise.reject("reject-boom");
console.log("reject unexpectedly resolved");
} catch (e: any) { console.log("reject caught:", e); }
}

syncCatch();
await noPriorAwait();
await directPostAwait();
await callPostAwait();
await promiseResolvePostAwait();
await rejectedAwaitStillWorks();
console.log("done");
29 changes: 29 additions & 0 deletions test-files/test_parity_builtin_static_name_length_3655.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let failures = 0;
function check(label: string, actual: any, expected: any): void {
if (actual !== expected) { console.log(label, actual, expected); failures++; }
}
function checkDataDescriptor(label: string, desc: any, value: any): void {
if (desc === undefined) { failures++; return; }
check(label + ".value", desc.value, value);
check(label + ".writable", desc.writable, false);
check(label + ".enumerable", desc.enumerable, false);
check(label + ".configurable", desc.configurable, true);
}
checkDataDescriptor("Array.from.name", Object.getOwnPropertyDescriptor(Array.from, "name"), "from");
checkDataDescriptor("Array.from.length", Object.getOwnPropertyDescriptor(Array.from, "length"), 1);
check("BigInt.asIntN.length", BigInt.asIntN.length, 2);
check("Reflect.apply.name", Reflect.apply.name, "apply");
check("Reflect.apply.length", Reflect.apply.length, 3);
checkDataDescriptor("Reflect.apply.length", Object.getOwnPropertyDescriptor(Reflect.apply, "length"), 3);
checkDataDescriptor("Math.max.length", Object.getOwnPropertyDescriptor(Math.max, "length"), 2);
checkDataDescriptor("ArrayBuffer.isView.name", Object.getOwnPropertyDescriptor(ArrayBuffer.isView, "name"), "isView");
checkDataDescriptor("Array.name", Object.getOwnPropertyDescriptor(Array, "name"), "Array");
checkDataDescriptor("Array.length", Object.getOwnPropertyDescriptor(Array, "length"), 1);
checkDataDescriptor("Map.name", Object.getOwnPropertyDescriptor(Map, "name"), "Map");
checkDataDescriptor("Map.length", Object.getOwnPropertyDescriptor(Map, "length"), 0);
checkDataDescriptor("Date.name", Object.getOwnPropertyDescriptor(Date, "name"), "Date");
checkDataDescriptor("Date.length", Object.getOwnPropertyDescriptor(Date, "length"), 7);
checkDataDescriptor("DataView.name", Object.getOwnPropertyDescriptor(DataView, "name"), "DataView");
checkDataDescriptor("DataView.length", Object.getOwnPropertyDescriptor(DataView, "length"), 1);
if (failures !== 0) throw new Error("builtin name/length descriptor parity failed");
console.log("builtin name/length descriptor parity ok");
5 changes: 5 additions & 0 deletions test-files/test_parity_chained_cross_module_getter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { VM } from "./fixtures/parity_5891/chained_cross_module_getter/lib.ts";
const vm = new VM();
console.log("chain=" + vm.viewport.scroll.scrollTop);
const scroll = vm.viewport.scroll;
console.log("local=" + scroll.scrollTop);
Loading
Loading