From 96c1415d0a3cdd536a1e6b0a266a18e0e408ae95 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Mon, 17 Jun 2013 16:31:04 -0400 Subject: [PATCH] Bug 883358 part 1. When creating getter/setter functions for the JSPROP_NATIVE_ACCESSORS case in JS_DefineProperties/JS_DefineProperty, give them the name of the property. r=till --- js/src/jsapi.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp index ceacf8e29e2..a5fd8d57941 100644 --- a/js/src/jsapi.cpp +++ b/js/src/jsapi.cpp @@ -3853,10 +3853,15 @@ DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, HandleValue val */ if (attrs & JSPROP_NATIVE_ACCESSORS) { JS_ASSERT(!(attrs & (JSPROP_GETTER | JSPROP_SETTER))); + JSFunction::Flags zeroFlags = JSAPIToJSFunctionFlags(0); + // We can't just use JS_NewFunctionById here because it + // assumes a string id. + RootedAtom atom(cx, JSID_IS_ATOM(id) ? JSID_TO_ATOM(id) : nullptr); attrs &= ~JSPROP_NATIVE_ACCESSORS; if (getter) { RootedObject global(cx, (JSObject*) &obj->global()); - JSFunction *getobj = JS_NewFunction(cx, (Native) getter, 0, 0, global, NULL); + JSFunction *getobj = NewFunction(cx, NullPtr(), (Native) getter, 0, + zeroFlags, global, atom); if (!getobj) return false; @@ -3870,7 +3875,8 @@ DefinePropertyById(JSContext *cx, HandleObject obj, HandleId id, HandleValue val // Root just the getter, since the setter is not yet a JSObject. AutoRooterGetterSetter getRoot(cx, JSPROP_GETTER, &getter, NULL); RootedObject global(cx, (JSObject*) &obj->global()); - JSFunction *setobj = JS_NewFunction(cx, (Native) setter, 1, 0, global, NULL); + JSFunction *setobj = NewFunction(cx, NullPtr(), (Native) setter, 1, + zeroFlags, global, atom); if (!setobj) return false;