forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.js
More file actions
101 lines (84 loc) · 2.44 KB
/
error.js
File metadata and controls
101 lines (84 loc) · 2.44 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// RUN: %hermes -O -target=HBC %s | %FileCheck --match-full-lines %s
// RUN: %hermes -O -target=HBC -emit-binary -out %t.hbc %s && %hermes %t.hbc | %FileCheck --match-full-lines %s
var e = new Error();
print(e);
//CHECK: Error
print(e.hasOwnProperty(e, 'name'));
//CHECK-NEXT: false
print(e.hasOwnProperty(e, 'message'));
//CHECK-NEXT: false
print(e.__proto__.hasOwnProperty('name'));
//CHECK-NEXT: true
print(e.__proto__.hasOwnProperty('message'));
//CHECK-NEXT: true
try { Error.prototype.toString.call(undefined); } catch (e) { print(e.name); }
//CHECK-NEXT: TypeError
try { Error.prototype.toString.call('string'); } catch (e) { print(e.name); }
//CHECK-NEXT: TypeError
try { Error.prototype.toString.call(11); } catch (e) { print(e.name); }
//CHECK-NEXT: TypeError
try { Error.prototype.toString.call(Symbol()); } catch (e) { print(e.name); }
//CHECK-NEXT: TypeError
e.name = 'RandomError';
print(e);
//CHECK-NEXT: RandomError
e.message = 'random-message';
print(e);
//CHECK-NEXT: RandomError: random-message
e.name = '';
print(e);
//CHECK-NEXT: random-message
e = new Error(undefined);
print(e.hasOwnProperty(e, 'message'));
//CHECK-NEXT: false
e = new Error('another-message');
print(e);
//CHECK-NEXT: Error: another-message
e = new TypeError();
print(e);
//CHECK-NEXT: TypeError
print(e.hasOwnProperty(e, 'name'));
//CHECK-NEXT: false
print(e.hasOwnProperty(e, 'message'));
//CHECK-NEXT: false
print(e.__proto__.hasOwnProperty('name'));
//CHECK-NEXT: true
print(e.__proto__.hasOwnProperty('message'));
//CHECK-NEXT: true
e = new ReferenceError('ref');
print(e);
//CHECK-NEXT: ReferenceError: ref
print(ReferenceError.__proto__ === Error);
//CHECK-NEXT: true
print(EvalError.__proto__ === Error);
//CHECK-NEXT: true
e = new Error();
e.name = 12345;
print(e);
// CHECK-NEXT: 12345
e.message = 67890;
print(e);
// CHECK-NEXT: 12345: 67890
// Check exception case of accessing Error.stack from a different 'this'
try {
new Error().__lookupGetter__("stack").call({});
} catch (e) {
print(e.name);
}
//CHECK-NEXT: TypeError
// Regression test: setting the stack while getting the message causes a null dereference.
e = new Error();
Object.defineProperty(e, "message", {
get: function () {
e.stack = {}
},
});
print(e.stack);
//CHECK-NEXT: Error
//CHECK-NEXT: at global{{.*}}