void MongoHelpersInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) {
    ObjectWrapper protoWrapper(cx, proto);
    ObjectWrapper globalWrapper(cx, global);

    // Initialize the reflection API and move it under the MongoHelpers object
    uassert(ErrorCodes::JSInterpreterFailure,
            "Error initializing javascript reflection API",
            JS_InitReflectParse(cx, global));
    JS::RootedValue reflectValue(cx);
    globalWrapper.getValue(kReflectName, &reflectValue);
    globalWrapper.deleteProperty(kReflectName);
    protoWrapper.setValue(kReflectName, reflectValue);

    JS::RootedValue exports(cx);
    getScope(cx)->execSetup(JSFiles::mongohelpers);
    globalWrapper.getValue(kExportsObjectName, &exports);
    globalWrapper.deleteProperty(kExportsObjectName);

    ObjectWrapper exportsWrapper(cx, exports);
    JS::RootedValue copyExport(cx);
    exportsWrapper.enumerate([&](JS::HandleId _id) {
        exportsWrapper.getValue(_id, &copyExport);
        protoWrapper.setValue(_id, copyExport);
        return true;
    });
}
Пример #2
0
void MaxKeyInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) {
    ObjectWrapper protoWrapper(cx, proto);

    JS::RootedValue value(cx);
    getScope(cx)->getProto<MaxKeyInfo>().newObject(&value);

    ObjectWrapper(cx, global).setValue(InternedString::MaxKey, value);
    protoWrapper.setValue(InternedString::singleton, value);
}