diff --git a/context.go b/context.go index e444e5e1..55773550 100644 --- a/context.go +++ b/context.go @@ -169,7 +169,10 @@ func valueResult(ctx *Context, rtn C.RtnValue) (*Value, error) { return &Value{rtn.value, ctx}, nil } -func valueStrings(ctx *Context, rtn C.RtnStrings) []string { +func valueStrings(ctx *Context, rtn C.RtnStrings) ([]string, error) { + if rtn.strings == nil { + return []string{}, newJSError(rtn.error) + } length := rtn.length slice := (*[1 << 28]*C.char)(unsafe.Pointer(rtn.strings))[:length:length] var result []string @@ -179,7 +182,7 @@ func valueStrings(ctx *Context, rtn C.RtnStrings) []string { result = append(result, C.GoString(s)) } defer C.free(unsafe.Pointer(rtn.strings)) - return result + return result, nil } func objectResult(ctx *Context, rtn C.RtnValue) (*Object, error) { diff --git a/object.go b/object.go index 41ad4bd3..f3c54c3c 100644 --- a/object.go +++ b/object.go @@ -86,7 +86,7 @@ func (o *Object) SetIdx(idx uint32, val interface{}) error { // Returns an array containing the names of the enumerable properties of this object, // including properties from prototype objects -func (o *Object) GetEnumerablePropertyNames() []string { +func (o *Object) GetEnumerablePropertyNames() ([]string, error) { rtn := C.ObjectGetPropertyNames(o.ptr) return valueStrings(o.ctx, rtn) } diff --git a/object_test.go b/object_test.go index 54c375ba..f89206cc 100644 --- a/object_test.go +++ b/object_test.go @@ -204,7 +204,8 @@ func TestGetEnumerablePropertyNames(t *testing.T) { obj.Set("hello", "world") expectedProperties := []string{"bar2", "foo", "hello"} - properties := obj.GetEnumerablePropertyNames() + properties, err := obj.GetEnumerablePropertyNames() + fatalIf(t, err) if !reflect.DeepEqual(properties, expectedProperties) { t.Error("properteis are not the same") diff --git a/v8go.cc b/v8go.cc index 1296f07f..4607e56f 100644 --- a/v8go.cc +++ b/v8go.cc @@ -1294,14 +1294,21 @@ RtnStrings ObjectGetPropertyNames(ValuePtr ptr) { LOCAL_OBJECT(ptr); RtnStrings rtn = {}; - MaybeLocal maybe_names = obj->GetPropertyNames(local_ctx); - Local names = maybe_names.ToLocalChecked(); + Local names; + if (!obj->GetPropertyNames(local_ctx).ToLocal(&names)) { + rtn.error = ExceptionError(try_catch, iso, local_ctx); + return rtn; + } uint32_t length = names->Length(); const char** strings = new const char*[length]; for (uint32_t i = 0; i < length; i++) { - Local name_from_array = names->Get(local_ctx, i).ToLocalChecked(); + Local name_from_array; + if (!names->Get(local_ctx, i).ToLocal(&name_from_array)) { + rtn.error = ExceptionError(try_catch, iso, local_ctx); + return rtn; + } String::Utf8Value ds(iso, name_from_array); strings[i] = CopyString(ds); }