mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-18 23:47:48 +02:00
36 lines
668 B
Go
36 lines
668 B
Go
|
package eval
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strconv"
|
||
|
|
||
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
||
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
||
|
"github.com/mafredri/cdp/protocol/runtime"
|
||
|
)
|
||
|
|
||
|
func PrepareEval(exp string) string {
|
||
|
return fmt.Sprintf("((function () {%s})())", exp)
|
||
|
}
|
||
|
|
||
|
func Unmarshal(obj *runtime.RemoteObject) (core.Value, error) {
|
||
|
if obj == nil {
|
||
|
return values.None, nil
|
||
|
}
|
||
|
|
||
|
switch obj.Type {
|
||
|
case "string":
|
||
|
str, err := strconv.Unquote(string(obj.Value))
|
||
|
|
||
|
if err != nil {
|
||
|
return values.None, err
|
||
|
}
|
||
|
|
||
|
return values.NewString(str), nil
|
||
|
case "undefined", "null":
|
||
|
return values.None, nil
|
||
|
default:
|
||
|
return values.Unmarshal(obj.Value)
|
||
|
}
|
||
|
}
|