summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/d5/tengo/objects/builtin_json.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2019-04-06 22:18:25 +0200
committerGitHub <noreply@github.com>2019-04-06 22:18:25 +0200
commit115d20373c21b107a428a55247c64f900e116038 (patch)
treec7299b3d3be2a48c0f2d5bfbd856cbd1b27d2e55 /vendor/github.com/d5/tengo/objects/builtin_json.go
parentcdf33e5748c110e12097130bdb44637e3d14b229 (diff)
downloadmatterbridge-msglm-115d20373c21b107a428a55247c64f900e116038.tar.gz
matterbridge-msglm-115d20373c21b107a428a55247c64f900e116038.tar.bz2
matterbridge-msglm-115d20373c21b107a428a55247c64f900e116038.zip
Update tengo vendor and load the stdlib. Fixes #789 (#792)
Diffstat (limited to 'vendor/github.com/d5/tengo/objects/builtin_json.go')
-rw-r--r--vendor/github.com/d5/tengo/objects/builtin_json.go60
1 files changed, 0 insertions, 60 deletions
diff --git a/vendor/github.com/d5/tengo/objects/builtin_json.go b/vendor/github.com/d5/tengo/objects/builtin_json.go
deleted file mode 100644
index b3413651..00000000
--- a/vendor/github.com/d5/tengo/objects/builtin_json.go
+++ /dev/null
@@ -1,60 +0,0 @@
-package objects
-
-import (
- "encoding/json"
-
- "github.com/d5/tengo"
-)
-
-// to_json(v object) => bytes
-func builtinToJSON(args ...Object) (Object, error) {
- if len(args) != 1 {
- return nil, ErrWrongNumArguments
- }
-
- res, err := json.Marshal(objectToInterface(args[0]))
- if err != nil {
- return &Error{Value: &String{Value: err.Error()}}, nil
- }
-
- if len(res) > tengo.MaxBytesLen {
- return nil, ErrBytesLimit
- }
-
- return &Bytes{Value: res}, nil
-}
-
-// from_json(data string/bytes) => object
-func builtinFromJSON(args ...Object) (Object, error) {
- if len(args) != 1 {
- return nil, ErrWrongNumArguments
- }
-
- var target interface{}
-
- switch o := args[0].(type) {
- case *Bytes:
- err := json.Unmarshal(o.Value, &target)
- if err != nil {
- return &Error{Value: &String{Value: err.Error()}}, nil
- }
- case *String:
- err := json.Unmarshal([]byte(o.Value), &target)
- if err != nil {
- return &Error{Value: &String{Value: err.Error()}}, nil
- }
- default:
- return nil, ErrInvalidArgumentType{
- Name: "first",
- Expected: "bytes/string",
- Found: args[0].TypeName(),
- }
- }
-
- res, err := FromInterface(target)
- if err != nil {
- return nil, err
- }
-
- return res, nil
-}