From 7cecc39fd8c2b80a82dc6da556d83d4833e379bc Mon Sep 17 00:00:00 2001 From: Guillaume Ballet Date: Fri, 28 Jun 2019 09:25:15 +0200 Subject: [PATCH] console: fix a couple panics --- internal/jsre/jsre.go | 2 +- internal/jsre/pretty.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/jsre/jsre.go b/internal/jsre/jsre.go index 7d1f63ed00..72a39be36c 100644 --- a/internal/jsre/jsre.go +++ b/internal/jsre/jsre.go @@ -320,7 +320,7 @@ func (re *JSRE) Compile(filename string, src string) (err error) { } func compileAndRun(vm *goja.Runtime, filename string, src string) (goja.Value, error) { - script, err := goja.Compile(filename, src, true) + script, err := goja.Compile(filename, src, false) if err != nil { return goja.Null(), err } diff --git a/internal/jsre/pretty.go b/internal/jsre/pretty.go index e41794b5f7..857172a048 100644 --- a/internal/jsre/pretty.go +++ b/internal/jsre/pretty.go @@ -226,8 +226,15 @@ func iterOwnAndConstructorKeys(vm *goja.Runtime, obj *goja.Object, f func(string } func iterOwnKeys(vm *goja.Runtime, obj *goja.Object, f func(string)) { - getOwnPropertyNames, _ := goja.AssertFunction(vm.Get("Object.getOwnPropertyNames")) - rv, _ := getOwnPropertyNames(obj) + Object := vm.Get("Object").ToObject(vm) + getOwnPropertyNames, isFunc := goja.AssertFunction(Object.Get("getOwnPropertyNames")) + if !isFunc { + panic(vm.ToValue("Object.getOwnPropertyNames isn't a function")) + } + rv, err := getOwnPropertyNames(goja.Null(), obj) + if err != nil { + panic(vm.ToValue(fmt.Sprintf("Error getting object properties: %v", err))) + } gv := rv.Export() switch gv := gv.(type) { case []interface{}: @@ -251,11 +258,12 @@ func (ctx ppctx) isBigNumber(v *goja.Object) bool { } } // Handle default constructor. - BigNumber := ctx.vm.Get("BigNumber.prototype").ToObject(ctx.vm) + BigNumber := ctx.vm.Get("BigNumber").ToObject(ctx.vm) if BigNumber == nil { return false } - isPrototypeOf, exists := goja.AssertFunction(BigNumber.Get("isPrototypeOf")) + prototype := BigNumber.Get("prototype").ToObject(ctx.vm) + isPrototypeOf, exists := goja.AssertFunction(prototype.Get("isPrototypeOf")) if !exists { return false }