-
Notifications
You must be signed in to change notification settings - Fork 1
/
Errors.js
231 lines (203 loc) · 7.41 KB
/
Errors.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
try {
eval("1 + 1")
} catch (error) {
throw EvalError("Cannot use eval, so this code won't work.")
}
try {
with (12) {}
} catch (error) {
throw SyntaxError("This is in strict mode? The code won't work.\n" +
"Unfortunately, some errors can only be thrown in non-strict mode, and some errors can only be thrown in module code. Oh well")
}
function getCodeParseError (code) {
try {
eval(code)
} catch (error) {
return error
}
return "Whatever JS implementation you're using has a bug."
}
function getCodeEvaluationError (code) {
return getCodeParseError(code)
}
const [log, finish] = (function closure () {
let errors = []
function add (...args) {
errors.push(...args)
}
return [add, () => console.log(errors)]
})()
const revokedProxy = (function closure () {
let revocable = Proxy.revocable({}, {})
revocable.revoke()
return revocable.proxy
})()
const revokedFunctionProxy = (function closure () {
let revocable = Proxy.revocable(function(){}, {})
revocable.revoke()
return revocable.proxy
})()
const exampleObject = (function closure () {
let example = {}
Object.defineProperty(example, 'nonWritableNumber', {value: 0, writable: false})
Object.defineProperty(example, 'nonSettableNumber', {get() {return 7}})
})()
const exampleNonExtensibleObject = Object.preventExtensions({})
const badProxy1 = new Proxy({}, {
getOwnPropertyDescriptor() {
return {
get: 7
}
}
})
const badProxy2 = new Proxy({}, {
getOwnPropertyDescriptor() {
return {
set: 7
}
}
})
const badProxy3 = new Proxy({}, {
getOwnPropertyDescriptor() {
return {
get: 7,
writable: false
}
}
})
log(getCodeParseError('[')) // See 5.1.4
log(getCodeParseError('let x, x'))
log(getCodeParseError('var x; let x'))
log(getCodeParseError('label: label: 1'))
log(getCodeParseError('break label'))
log(getCodeParseError('continue label'))
// <Script StatementList Statement VariableStatement BindingIdentifier>
log(getCodeParseError('"use strict"; var eval'))
log(getCodeParseError('"use strict"; var yield'))
// <Still BindingIdentifier, but different thing. In this case a generator _expression_>
log(getCodeParseError('(function* yield () {})'))
log(getCodeParseError('async await => 1'))
log(getCodeParseError('1 = 1'))
log(getCodeParseError('1++'))
log(getCodeParseError('++1'))
log(getCodeParseError('var 1')) // Only different because of browsers
log(getCodeParseError('"use strict"; var a = [eval] = [1]'))
log(getCodeParseError('var [...[1, 2]] = []'))
log(getCodeParseError('var {...[x, y]} = [1, 2]'))
log(getCodeParseError('var [[1]] = [[8]]'))
log(getCodeParseError('"use strict"; var [[eval]] = [[8]]'))
log(getCodeParseError('"use strict"; var eval = 8'))
log(getCodeParseError('var x = {superMethod} = {superMethod() {super()}}'))
log(getCodeParseError('if (true) label: function a () {};'))
// <Only different because of Browsers, see B.3.2>
log(getCodeParseError('"use strict"; if (true) label: function a () {};'))
log(getCodeEvaluationError('1n ** -1n'))
log(getCodeEvaluationError('1n / 0n'))
log(getCodeEvaluationError('0n % 0n'))
log(getCodeEvaluationError('2n >>> 1n'))
// todo: 6.1.7.2
log(getCodeEvaluationError('undefinedVariable'))
// I don't see any way to make PutValue throw in step 3
log(getCodeEvaluationError('"use strict"; undefinedVariable = 1'))
log(getCodeEvaluationError('exampleObject.nonWritableNumber++'))
log(getCodeEvaluationError('exampleObject.nonSettableNumber++'))
log(getCodeEvaluationError('exampleNonExtensibleObject.nonExistentProperty++'))
log(getCodeEvaluationError('Object.defineProperty({}, "property", "not object")'))
log(getCodeEvaluationError('Object.defineProperty({}, "property", {get: 7})'))
log(getCodeEvaluationError('Object.defineProperty({}, "property", {set: 7})'))
log(getCodeEvaluationError('Object.defineProperty({}, "property", {set: 7, writable: false})'))
log(getCodeEvaluationError('new ArrayBuffer(1e300)'))
log(getCodeEvaluationError('new SharedArrayBuffer(1e300)'))
log(getCodeEvaluationError('1 + ({[Symbol.toPrimitive](){return {}}})'))
log(getCodeEvaluationError('1 + ({valueOf(){return {}}, toString(){return {}}})'))
log(getCodeEvaluationError('+Symbol()'))
log(getCodeEvaluationError('+2n'))
log(getCodeEvaluationError('BigInt.asIntN(2, undefined)'))
log(getCodeEvaluationError('BigInt.asIntN(2, null)'))
log(getCodeEvaluationError('BigInt.asIntN(2, 5)'))
log(getCodeEvaluationError('BigInt.asIntN(2, 7)')) // Only different because of browsers
log(getCodeEvaluationError('BigInt.asIntN(2, "NaN")')) // For some reason this throws a SyntaxError when run.
log(getCodeEvaluationError('"" + Symbol()'))
log(getCodeEvaluationError('Object.assign(undefined)'))
log(getCodeEvaluationError('Object.assign(null)'))
log(getCodeEvaluationError('BigInt.asIntN(2.5, 5n)'))
log(getCodeEvaluationError('BigInt.asIntN(-7, 5n)'))
log(getCodeEvaluationError('Array.isArray(revokedProxy)'))
log(getCodeEvaluationError('let array = []; array[2**32 - 2] = 7; array.push("another value")'))
log(getCodeEvaluationError('JSON.stringify([], revokedProxy)'))
class RidiculousArray extends new Proxy(Array, {
construct (target, args) {
let value = new target(...args)
Object.defineProperty(value, "2", {
value: 7,
writable: false,
configurable: false
})
return value
}
}) {}
log(getCodeEvaluationError('RidiculousArray.from(new RidiculousArray())'))
console.log('There some errors that could theoretically happen if computers could do some Array functions 2**32 times without crashing')
log(getCodeEvaluationError(`
Object.defineProperty(
Object.defineProperty({}, "property", {"configurable": false}),
"property",
{"configurable": true}
)
`))
log(getCodeEvaluationError(`
let temporaryValue = new Proxy(
[,,1,,2], // Empty Empty 1 Empty 2
{
deleteProperty (...args) {return false}
}
)
temporaryValue.copyWithin(3)
`))
log(getCodeEvaluationError('1 + ({[Symbol.toPrimitive]: "Not a function!?"})'))
log(getCodeEvaluationError('1 + ({[Symbol.toPrimitive]: "A different string"})')) // Only different because of browsers
log(getCodeEvaluationError('1 + ({toString: "Not a function!?"}).toLocaleString()'))
log(getCodeEvaluationError('1 + ({toString: "A different string"}).toLocaleString()')) // Only different because of browsers
log(getCodeEvaluationError(`
let badProxy = new Proxy({}, {
ownKeys() {return "Not an object!?"}
})
badProxy.getOwnPropertyKeys()
`))
log(getCodeEvaluationError(`
let badProxy = new Proxy({}, {
ownKeys() {return [false]}
})
Object.getOwnPropertyNames(badProxy)
`))
log(getCodeEvaluationError(`Function.prototype[Symbol.hasInstance]({prototype: 12})`))
log(getCodeEvaluationError(`
let silly = /regex/
silly.constructor = "uh..."
silly[Symbol.matchAll]()
`))
log(getCodeEvaluationError(`
let sillyRegex = /regex/
sillyRegex.constructor = {
[Symbol.species]: "uh..."
}
sillyRegex[Symbol.matchAll]()
`))
log(getCodeEvaluationError(`
let sillyArray = []
sillyArray.constructor = revokedFunctionProxy
sillyArray.concat()
`))
log(getCodeEvaluationError(`
let sillyIterable = []
sillyIterable[Symbol.iterator] = (..._args) => "Wow"
new Set(sillyIterable)
`))
log(getCodeEvaluationError(`
let sillyIterable = []
sillyIterable[Symbol.iterator] = (..._args) => ({
next () {return "Wow"}
})
new Set(sillyIterable)
`))
finish()