summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/mozjs/objectwrapper.cpp
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2019-01-11 19:27:20 +0000
committerGabriel Russell <gabriel.russell@mongodb.com>2019-01-29 23:06:10 +0000
commita3d232b697dfc7c8833fc1855abbc190fe0d5970 (patch)
treefb02e9d3383f6342944fc4f2cd494ea86d42a92a /src/mongo/scripting/mozjs/objectwrapper.cpp
parent941c4fbab21029e3bbe577d953250116cd0e8533 (diff)
downloadmongo-a3d232b697dfc7c8833fc1855abbc190fe0d5970.tar.gz
SERVER-29286 import and use mozjs-60
Diffstat (limited to 'src/mongo/scripting/mozjs/objectwrapper.cpp')
-rw-r--r--src/mongo/scripting/mozjs/objectwrapper.cpp51
1 files changed, 41 insertions, 10 deletions
diff --git a/src/mongo/scripting/mozjs/objectwrapper.cpp b/src/mongo/scripting/mozjs/objectwrapper.cpp
index 61030ce0274..01bb79a8890 100644
--- a/src/mongo/scripting/mozjs/objectwrapper.cpp
+++ b/src/mongo/scripting/mozjs/objectwrapper.cpp
@@ -109,29 +109,57 @@ void ObjectWrapper::Key::set(JSContext* cx, JS::HandleObject o, JS::HandleValue
void ObjectWrapper::Key::define(JSContext* cx,
JS::HandleObject o,
JS::HandleValue value,
- unsigned attrs,
- JSNative getter,
- JSNative setter) {
+ unsigned attrs) {
switch (_type) {
case Type::Field:
- if (JS_DefineProperty(cx, o, _field, value, attrs, getter, setter))
+ if (JS_DefineProperty(cx, o, _field, value, attrs))
return;
break;
case Type::Index:
- if (JS_DefineElement(cx, o, _idx, value, attrs, getter, setter))
+ if (JS_DefineElement(cx, o, _idx, value, attrs))
return;
break;
case Type::Id: {
JS::RootedId id(cx, _id);
- if (JS_DefinePropertyById(cx, o, id, value, attrs, getter, setter))
+ if (JS_DefinePropertyById(cx, o, id, value, attrs))
return;
break;
}
case Type::InternedString: {
InternedStringId id(cx, _internedString);
- if (JS_DefinePropertyById(cx, o, id, value, attrs, getter, setter))
+ if (JS_DefinePropertyById(cx, o, id, value, attrs))
+ return;
+ break;
+ }
+ }
+
+ throwCurrentJSException(cx, ErrorCodes::InternalError, "Failed to define value on a JSObject");
+}
+
+void ObjectWrapper::Key::define(
+ JSContext* cx, JS::HandleObject o, unsigned attrs, JSNative getter, JSNative setter) {
+ switch (_type) {
+ case Type::Field:
+ if (JS_DefineProperty(cx, o, _field, getter, setter, attrs))
+ return;
+ break;
+ case Type::Index:
+ if (JS_DefineElement(cx, o, _idx, getter, setter, attrs))
+ return;
+ break;
+ case Type::Id: {
+ JS::RootedId id(cx, _id);
+
+ if (JS_DefinePropertyById(cx, o, id, getter, setter, attrs))
+ return;
+ break;
+ }
+ case Type::InternedString: {
+ InternedStringId id(cx, _internedString);
+
+ if (JS_DefinePropertyById(cx, o, id, getter, setter, attrs))
return;
break;
}
@@ -390,9 +418,12 @@ void ObjectWrapper::setPrototype(JS::HandleObject object) {
throwCurrentJSException(_context, ErrorCodes::InternalError, "Failed to set prototype");
}
-void ObjectWrapper::defineProperty(
- Key key, JS::HandleValue val, unsigned attrs, JSNative getter, JSNative setter) {
- key.define(_context, _object, val, attrs, getter, setter);
+void ObjectWrapper::defineProperty(Key key, JS::HandleValue val, unsigned attrs) {
+ key.define(_context, _object, val, attrs);
+}
+
+void ObjectWrapper::defineProperty(Key key, unsigned attrs, JSNative getter, JSNative setter) {
+ key.define(_context, _object, attrs, getter, setter);
}
void ObjectWrapper::deleteProperty(Key key) {