mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-19 00:31:06 +00:00
Squashed 'engine262/' content from commit ae71998
git-subtree-dir: engine262 git-subtree-split: ae71998cc5a8315700555135b1ac202a0d6d0b31
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
import { expect, test } from 'vitest';
|
||||
import {
|
||||
Agent, isPromiseObject, JSStringValue, ManagedRealm, NormalCompletion, setSurroundingAgent,
|
||||
type PromiseObject,
|
||||
} from '#self';
|
||||
|
||||
test('stack', () => {
|
||||
const agent = new Agent();
|
||||
setSurroundingAgent(agent);
|
||||
const realm = new ManagedRealm();
|
||||
const result = realm.evaluateScript(`
|
||||
function x() { throw new Error('owo'); }
|
||||
function y() { x(); }
|
||||
try {
|
||||
y();
|
||||
} catch (e) {
|
||||
e.stack;
|
||||
}
|
||||
`) as NormalCompletion<JSStringValue>;
|
||||
expect(result).toBeInstanceOf(NormalCompletion);
|
||||
expect(result.Value).toBeInstanceOf(JSStringValue);
|
||||
expect(result.Value.stringValue()).toMatchInlineSnapshot(`
|
||||
"Error: owo
|
||||
at x (<anonymous>:2:36)
|
||||
at y (<anonymous>:3:20)
|
||||
at <anonymous>:5:7"
|
||||
`);
|
||||
});
|
||||
|
||||
test('async stack', () => {
|
||||
const agent = new Agent();
|
||||
setSurroundingAgent(agent);
|
||||
const realm = new ManagedRealm();
|
||||
const result = realm.evaluateScript(`
|
||||
async function x() { await 1; throw new Error('owo'); }
|
||||
async function y() { await x(); }
|
||||
y().catch((e) => e.stack);
|
||||
`) as NormalCompletion<PromiseObject>;
|
||||
expect(result).toBeInstanceOf(NormalCompletion);
|
||||
expect(isPromiseObject(result.Value)).toBe(true);
|
||||
expect(result.Value.PromiseState).toBe('fulfilled');
|
||||
if (!(result.Value.PromiseResult instanceof JSStringValue)) {
|
||||
throw new Error('Expected JSStringValue');
|
||||
}
|
||||
expect(result.Value.PromiseResult.stringValue()).toMatchInlineSnapshot(`
|
||||
"Error: owo
|
||||
at async x (<anonymous>:2:51)
|
||||
at async y (<anonymous>:3:32)"
|
||||
`);
|
||||
});
|
||||
|
||||
test('native stack', () => {
|
||||
const agent = new Agent();
|
||||
setSurroundingAgent(agent);
|
||||
const realm = new ManagedRealm();
|
||||
const result = realm.evaluateScript(`
|
||||
function x() { Reflect.get(); }
|
||||
try {
|
||||
x();
|
||||
} catch (e) {
|
||||
e.stack;
|
||||
}
|
||||
`) as NormalCompletion<JSStringValue>;
|
||||
expect(result).toBeInstanceOf(NormalCompletion);
|
||||
expect(result.Value).toBeInstanceOf(JSStringValue);
|
||||
expect(result.Value.stringValue()).toMatchInlineSnapshot(`
|
||||
"TypeError: undefined is not an object
|
||||
at get (native)
|
||||
at x (<anonymous>:2:20)
|
||||
at <anonymous>:4:7"
|
||||
`);
|
||||
});
|
||||
Reference in New Issue
Block a user