diff options
author | Jason Carey <jcarey@argv.me> | 2015-10-06 20:45:57 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2015-10-06 20:45:57 -0400 |
commit | 054b0faf2cc16e3d40d2d40ffdda1e219e4c24e3 (patch) | |
tree | 38cf21d16af837af7a0273cd76ef1bd3c1315e4b /src/mongo/scripting/mozjs/jsthread.cpp | |
parent | cad0c421371e55fdf65c0be4badd23120bec72c1 (diff) | |
download | mongo-054b0faf2cc16e3d40d2d40ffdda1e219e4c24e3.tar.gz |
SERVER-19977 Use JS_NewArrayObject directly
Rather than creating objects with stringified integer keys, just create
them directly with JS_NewArrayObject, which can take JS::CallArgs or
JS::AutoValueVector's directly.
Diffstat (limited to 'src/mongo/scripting/mozjs/jsthread.cpp')
-rw-r--r-- | src/mongo/scripting/mozjs/jsthread.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/mongo/scripting/mozjs/jsthread.cpp b/src/mongo/scripting/mozjs/jsthread.cpp index 2e5ea289d84..b257876afc6 100644 --- a/src/mongo/scripting/mozjs/jsthread.cpp +++ b/src/mongo/scripting/mozjs/jsthread.cpp @@ -88,17 +88,12 @@ public: "first argument must be a function", args.get(0).isObject() && JS_ObjectIsFunction(cx, args.get(0).toObjectOrNull())); - JS::RootedObject robj(cx, JS_NewPlainObject(cx)); - ObjectWrapper wobj(cx, robj); - for (unsigned i = 0; i < args.length(); ++i) { - // 10 decimal digits for a 32 bit unsigned, then 1 for the null - char buf[11]; - std::sprintf(buf, "%i", i); - - wobj.setValue(buf, args.get(i)); + JS::RootedObject robj(cx, JS_NewArrayObject(cx, args)); + if (!robj) { + uasserted(ErrorCodes::JSInterpreterFailure, "Failed to JS_NewArrayObject"); } - _sharedData->_args = wobj.toBSON(); + _sharedData->_args = ObjectWrapper(cx, robj).toBSON(); _sharedData->_stack = currentJSStackToString(cx); |