Debian Codegraph @

js/src/tests/test262/built-ins/NativeErrors/cause_property_native_error.js

raw
1 // Copyright (C) 2021 Chengzhong Wu. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: NativeError constructor creates own cause property
6 info: |
7 NativeError ( message[ , options ] )
8
9 ...
10 4. Perform ? InstallErrorCause(O, options).
11 ...
12
13 20.5.8.1 InstallErrorCause ( O, options )
14
15 1. If Type(options) is Object and ? HasProperty(options, "cause") is true, then
16 a. Let cause be ? Get(options, "cause").
17 b. Perform ! CreateNonEnumerableDataPropertyOrThrow(O, "cause", cause).
18 ...
19
20 esid: sec-nativeerror
21 features: [error-cause]
22 includes: [propertyHelper.js]
23 ---*/
24
25 var nativeErrors = [
26 EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError
27 ];
28
29 for (var i = 0; i < nativeErrors.length; ++i) {
30 var nativeError = nativeErrors[i];
31
32 var message = "my-message";
33 var cause = { message: "my-cause" };
34 var error = new nativeError(message, { cause });
35
36 verifyProperty(error, "cause", {
37 configurable: true,
38 enumerable: false,
39 writable: true,
40 value: cause,
41 });
42
43 verifyProperty(new nativeError(message), "cause", undefined);
44 verifyProperty(new nativeError(message, { cause: undefined }), "cause", { value: undefined });
45 }
46
47 reportCompare(0, 0);