Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
48 lines (46 loc) · 2.99 KB

File metadata and controls

48 lines (46 loc) · 2.99 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
WScript.LoadScriptFile("..\\UnitTestFramework\\UnitTestFramework.js");
testRunner.runTests([
{
name: "Helpers should not show up in stack traces",
body() {
for (const builtin of [Array.prototype.forEach, Array.prototype.filter, Array.prototype.flatMap]) {
assert.isTrue(typeof(builtin.name) === "string" && builtin.name.length > 0, `Test requires builtin.name to be set for ${builtin.toString()}`);
try {
builtin.call([1, 2, 3], function callback() { throw new Error("error in callback") });
assert.isTrue(false, `Exception swallowed from callback for ${builtin.name}`);
} catch (e) {
const frames = e.stack.split("\n");
assert.isTrue(/error in callback/.test(frames[0]), `Invalid first frame "${frames[0]}" for ${builtin.name}`);
assert.isTrue(/at callback \(/.test(frames[1]), `Invalid second frame "${frames[1]}" for ${builtin.name}`);
assert.isTrue(new RegExp(`at Array.prototype.${builtin.name} \\(native code\\)`, "i").test(frames[2]), `Invalid third frame "${frames[2]}" for ${builtin.name}`);
assert.isTrue(/at body \(/.test(frames[3]), `Invalid fourth frame "${frames[3]}" for ${builtin.name}`);
}
}
}
},
{
name: "(Existing) JsBuiltIns shouldn't be constructable",
body() {
for (const builtin of [
Array.prototype.values,
Array.prototype.entries,
Array.prototype.keys,
Array.prototype.indexOf,
Array.prototype.forEach,
Array.prototype.filter,
Array.prototype.flat,
Array.prototype.flatMap,
Object.fromEntries,
]) {
assert.isTrue(typeof(builtin.name) === "string" && builtin.name.length > 0, `Test requires builtin.name to be set for ${builtin.toString()}`);
assert.throws(() => new builtin(), TypeError, `${builtin.name} should not be constructable (using new)`, "Function is not a constructor");
assert.throws(() => Reflect.construct(builtin, []), TypeError, `${builtin.name} should not be constructable (using Reflect.construct target)`, "'target' is not a constructor");
assert.throws(() => Reflect.construct(function(){}, [], builtin), TypeError, `${builtin.name} should not be constructable (using Reflect.construct newTarget)`, "'newTarget' is not a constructor");
}
}
},
], { verbose: false });
Morty Proxy This is a proxified and sanitized view of the page, visit original site.