-
Notifications
You must be signed in to change notification settings - Fork 642
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: https://tc39.es/proposal-error-cause/ This is a stage 3 proposal to add a `cause` property to JSErrors when the option is provided in the constructor. Add a check in the Error constructor which checks for the property and defines it if it exists. Reviewed By: dulinriley Differential Revision: D27102691 fbshipit-source-id: 45c02c9ed009961a0442bd5c7534fc509310d26c
- Loading branch information
1 parent
06b4381
commit 56e7cda
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* 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 %s | %FileCheck --match-full-lines %s | ||
// RUN: %hermes -O -emit-binary -out %t.hbc %s && %hermes %t.hbc | %FileCheck --match-full-lines %s | ||
|
||
print('error cause'); | ||
// CHECK-LABEL: error cause | ||
|
||
try { | ||
try { | ||
throw Error("err1"); | ||
} catch (e1) { | ||
throw Error("err2", { cause: e1 }); | ||
} | ||
} catch (e2) { | ||
print(e2.message); | ||
// CHECK-NEXT: err2 | ||
print(e2.cause.message); | ||
// CHECK-NEXT: err1 | ||
} | ||
|
||
try { | ||
throw Error("err", {get cause() { | ||
print('getter'); | ||
return 'foo'; | ||
}}); | ||
// CHECK-NEXT: getter | ||
} catch (e) { | ||
print(e.message); | ||
// CHECK-NEXT: err | ||
print(e.cause); | ||
// CHECK-NEXT: foo | ||
} | ||
|
||
try { | ||
throw Error("err", {}); | ||
} catch (e) { | ||
print(e.message); | ||
// CHECK-NEXT: err | ||
print(Object.hasOwnProperty(e, 'cause')); | ||
// CHECK-NEXT: false | ||
} |