Skip to content

Commit

Permalink
Added Error cause
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroyk committed Aug 4, 2024
1 parent c665f0b commit a38ab17
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 26 additions & 1 deletion builtin_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,19 @@ func (r *Runtime) newErrorObject(proto *Object, class string) *errorObject {
func (r *Runtime) builtin_Error(args []Value, proto *Object) *Object {
obj := r.newErrorObject(proto, classError)
if len(args) > 0 && args[0] != _undefined {
obj._putProp("message", args[0], true, false, true)
obj._putProp("message", args[0].ToString(), true, false, true)
}
if len(args) > 1 && args[1] != _undefined {
if options, ok := args[1].(*Object); ok {
if options.hasProperty(asciiString("cause")) {
obj.defineOwnPropertyStr("cause", PropertyDescriptor{
Writable: FLAG_TRUE,
Enumerable: FLAG_FALSE,
Configurable: FLAG_TRUE,
Value: options.Get("cause"),
}, true)
}
}
}
return obj.val
}
Expand All @@ -138,6 +150,19 @@ func (r *Runtime) builtin_AggregateError(args []Value, proto *Object) *Object {
}
obj._putProp("errors", r.newArrayValues(errors), true, false, true)

if len(args) > 2 && args[2] != _undefined {
if options, ok := args[2].(*Object); ok {
if options.hasProperty(asciiString("cause")) {
obj.defineOwnPropertyStr("cause", PropertyDescriptor{
Writable: FLAG_TRUE,
Enumerable: FLAG_FALSE,
Configurable: FLAG_TRUE,
Value: options.Get("cause"),
}, true)
}
}
}

return obj.val
}

Expand Down
1 change: 0 additions & 1 deletion tc39_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ var (
"__setter__",
"ShadowRealm",
"SharedArrayBuffer",
"error-cause",
"decorators",
"regexp-v-flag",
}
Expand Down

0 comments on commit a38ab17

Please sign in to comment.