-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve extension engine (#298)
1. support onError event 2. add built-in MessageError
- Loading branch information
Showing
16 changed files
with
284 additions
and
79 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
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,29 @@ | ||
package error | ||
|
||
import ( | ||
"github.com/dop251/goja" | ||
) | ||
|
||
type MessageError struct { | ||
Message string `json:"message"` | ||
} | ||
|
||
func (e *MessageError) Error() string { | ||
return e.Message | ||
} | ||
|
||
func Enable(runtime *goja.Runtime) error { | ||
messageError := runtime.ToValue(func(call goja.ConstructorCall) *goja.Object { | ||
var message string | ||
if len(call.Arguments) > 0 { | ||
message = call.Arguments[0].String() | ||
} | ||
instance := &MessageError{ | ||
Message: message, | ||
} | ||
instanceValue := runtime.ToValue(instance).(*goja.Object) | ||
instanceValue.SetPrototype(call.This.Prototype()) | ||
return instanceValue | ||
}) | ||
return runtime.Set("MessageError", messageError) | ||
} |
This file was deleted.
Oops, something went wrong.
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,24 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/dop251/goja" | ||
) | ||
|
||
func ThrowTypeError(vm *goja.Runtime, msg string) { | ||
panic(vm.NewTypeError(msg)) | ||
} | ||
|
||
func AssertError[T error](err error) (t T, r bool) { | ||
if err == nil { | ||
return | ||
} | ||
if e, ok := err.(T); ok { | ||
return e, true | ||
} | ||
if e, ok := err.(*goja.Exception); ok { | ||
if ee, okk := e.Value().Export().(T); okk { | ||
return ee, true | ||
} | ||
} | ||
return | ||
} |
Oops, something went wrong.