|
@@ -1452,6 +1452,23 @@ func (r *Runtime) SetTimeSource(now Now) {
|
|
r.now = now
|
|
r.now = now
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// New is an equivalent of the 'new' operator allowing to call it directly from Go.
|
|
|
|
+func (r *Runtime) New(construct Value, args ...Value) (o *Object, err error) {
|
|
|
|
+ defer func() {
|
|
|
|
+ if x := recover(); x != nil {
|
|
|
|
+ switch x := x.(type) {
|
|
|
|
+ case *Exception:
|
|
|
|
+ err = x
|
|
|
|
+ case *InterruptedError:
|
|
|
|
+ err = x
|
|
|
|
+ default:
|
|
|
|
+ panic(x)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ return r.builtin_new(r.toObject(construct), args), nil
|
|
|
|
+}
|
|
|
|
+
|
|
// Callable represents a JavaScript function that can be called from Go.
|
|
// Callable represents a JavaScript function that can be called from Go.
|
|
type Callable func(this Value, args ...Value) (Value, error)
|
|
type Callable func(this Value, args ...Value) (Value, error)
|
|
|
|
|