cause_property.js (1027B)
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: Error constructor creates own cause property 6 info: | 7 Error ( 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-error-message 21 features: [error-cause] 22 includes: [propertyHelper.js] 23 ---*/ 24 25 var message = "my-message"; 26 var cause = { message: "my-cause" }; 27 var error = new Error(message, { cause }); 28 29 verifyProperty(error, "cause", { 30 configurable: true, 31 enumerable: false, 32 writable: true, 33 value: cause, 34 }); 35 36 verifyProperty(new Error(message), "cause", undefined); 37 verifyProperty(new Error(message, { cause: undefined }), "cause", { value: undefined }); 38 39 reportCompare(0, 0);