Esempio n. 1
0
void MozJSImplScope::setFunction(const char* field, const char* code) {
    MozJSEntry entry(this);

    JS::RootedValue fun(_context);

    _MozJSCreateFunction(code, getFunctionCache().size() + 1, &fun);

    ObjectWrapper(_context, _global).setValue(field, fun);
}
Esempio n. 2
0
File: engine.cpp Progetto: Nub/mongo
    ScriptingFunction Scope::createFunction(const char* code) {
        if (code[0] == '/' && code [1] == '*') {
            code += 2;
            while (code[0] && code[1]) {
                if (code[0] == '*' && code[1] == '/') {
                    code += 2;
                    break;
                }
                code++;
            }
        }

        map<string, ScriptingFunction>::iterator i = _cachedFunctions.find(code);
        if (i != _cachedFunctions.end())
            return i->second;
        // NB: we calculate the function number for v8 so the cache can be utilized to
        //     lookup the source on an exception, but SpiderMonkey uses the value
        //     returned by JS_CompileFunction.
        ScriptingFunction functionNumber = getFunctionCache().size() + 1;
        _cachedFunctions[code] = functionNumber;
        ScriptingFunction f = _createFunction(code, functionNumber);
        return f;
    }