예제 #1
0
파일: implscope.cpp 프로젝트: Jaryli/mongo
void MozJSImplScope::_MozJSCreateFunction(const char* raw,
                                          ScriptingFunction functionNumber,
                                          JS::MutableHandleValue fun) {
    std::string code = str::stream() << "_funcs" << functionNumber << " = "
                                     << parseJSFunctionOrExpression(_context, StringData(raw));

    JS::CompileOptions co(_context);
    setCompileOptions(&co);

    _checkErrorState(JS::Evaluate(_context, _global, co, code.c_str(), code.length(), fun));
    uassert(10232,
            "not a function",
            fun.isObject() && JS_ObjectIsFunction(_context, fun.toObjectOrNull()));
}
예제 #2
0
파일: implscope.cpp 프로젝트: alabid/mongo
// TODO: This function identification code is broken.  Fix it up to be more robust
//
// See: SERVER-16703 for more info
void MozJSImplScope::_MozJSCreateFunction(const char* raw,
                                          ScriptingFunction functionNumber,
                                          JS::MutableHandleValue fun) {
    std::string code = jsSkipWhiteSpace(raw);
    if (!hasFunctionIdentifier(code)) {
        if (code.find('\n') == std::string::npos && !hasJSReturn(code) &&
            (code.find(';') == std::string::npos || code.find(';') == code.size() - 1)) {
            code = "return " + code;
        }
        code = "function(){ " + code + "}";
    }

    code = str::stream() << "_funcs" << functionNumber << " = " << code;

    JS::CompileOptions co(_context);
    setCompileOptions(&co);

    _checkErrorState(JS::Evaluate(_context, _global, co, code.c_str(), code.length(), fun));
    uassert(10232,
            "not a function",
            fun.isObject() && JS_ObjectIsFunction(_context, fun.toObjectOrNull()));
}
예제 #3
0
void NumberDecimalInfo::make(JSContext* cx, JS::MutableHandleValue thisv, Decimal128 decimal) {
    auto scope = getScope(cx);

    scope->getProto<NumberDecimalInfo>().newObject(thisv);
    JS_SetPrivate(thisv.toObjectOrNull(), scope->trackedNew<Decimal128>(decimal));
}