nsresult nsScriptLoader::ProcessRequest(nsScriptLoadRequest* aRequest) { NS_ASSERTION(ReadyToExecuteScripts() && nsContentUtils::IsSafeToRunScript(), "Caller forgot to check ReadyToExecuteScripts()"); NS_ENSURE_ARG(aRequest); nsAFlatString* script; nsAutoString textData; // If there's no script text, we try to get it from the element if (aRequest->mIsInline) { // XXX This is inefficient - GetText makes multiple // copies. aRequest->mElement->GetScriptText(textData); script = &textData; } else { script = &aRequest->mScriptText; } FireScriptAvailable(NS_OK, aRequest); nsresult rv = EvaluateScript(aRequest, *script); FireScriptEvaluated(rv, aRequest); return rv; }
bool VJSGlobalContext::EvaluateScript( VFile *inFile, VValueSingle **outResult, bool inJSONresult ) const { VString script; bool ok = LoadScriptFile( inFile, script); if (ok) { VURL url( inFile->GetPath()); ok = EvaluateScript( script, &url, outResult, inJSONresult ); } return ok; }
ScriptRunner::ScriptRunner(QString script_file) { engine = new QScriptEngine(); helper = new ScriptHelper(engine); helper_value = new QScriptValue; *helper_value = engine->newQObject(helper); engine->globalObject().setProperty("helper", *helper_value); ret_val = NULL; script = "scripts/"+script_file; ReadFile(); EvaluateScript(); }
bool VJSContext::EvaluateScript( VFile *inFile, VJSValue *outResult, JS4D::ExceptionRef *outException, VJSObject* inThisObject) const { VString script; bool ok = LoadScriptFile( inFile, script); if (ok) { VURL url( inFile->GetPath()); ok = EvaluateScript( script, &url, outResult, outException, inThisObject); } return ok; }
NSScriptRunner::NSScriptRunner(QString script_file, Server* server, QMap<QString, QVariant> params, int requestId) { this->server = server; this->params = params; this->requestId = requestId; engine = new QScriptEngine(); helper = new NSScriptHelper(engine, server, this->params, requestId); helper_value = new QScriptValue; *helper_value = engine->newQObject(helper); engine->globalObject().setProperty("helper", *helper_value); ret_val = NULL; script = "scripts/"+script_file; ReadFile(); EvaluateScript(); }
bool VJSContext::GetFunction(const VString& inFunctionRef, VJSObject& outFuncObj) { bool found = false; VJSValue result(*this); EvaluateScript(inFunctionRef, nil, &result, nil, nil); if (result.IsObject()) { VJSObject funcobj(result.GetObject()); if (funcobj.IsFunction()) { outFuncObj = funcobj; found = true; } } return found; }
// ----------------------------------------------------------------------------- // CCFScript::ContextIndicationL // // ----------------------------------------------------------------------------- // void CCFScript::ContextIndicationL( CCFContextIndication* aIndication ) { FUNC_LOG; // Initialize local variables. TInt contextLevelDelay( 0 ); // Guards firing actions so that an operation of the script must have been // evaluated before actions are allowed to be fired. TBool evaluated = EvaluateScript( aIndication->Context(), contextLevelDelay ); delete aIndication; // Cleanup the transferred indication. aIndication = NULL; if ( evaluated ) { TInt err( KErrNone ); TRAP( err, iScriptRoot->ContextEvaluatedL( contextLevelDelay ) ); ERROR( err, "Signalling script evaluation by context to script root leaved." ); } }
static void TestSecurityManager(JSContext* jscontext, JSObject* glob, nsIXPConnect* xpc) { jsval rval; JSBool success = JS_TRUE; MySecMan* sm = new MySecMan(); nsTestXPCFoo* foo = new nsTestXPCFoo(); if(!sm || ! foo) { success = JS_FALSE; printf("FAILED to create object!\n"); goto sm_test_done; } rval = JSVAL_FALSE; { JSAutoRequest ar(jscontext); JS_SetProperty(jscontext, glob, "failed", &rval); } printf("Individual SecurityManager tests...\n"); if(NS_FAILED(xpc->SetSecurityManagerForJSContext(jscontext, sm, nsIXPCSecurityManager::HOOK_ALL))) { success = JS_FALSE; printf("SetSecurityManagerForJSContext FAILED!\n"); goto sm_test_done; } printf(" build wrapper with veto: TEST NOT RUN\n"); /* // This test is broken because xpconnect now detects that this is a // call from native code and lets it succeed without calling the security manager sm->SetMode(MySecMan::VETO_ALL); printf(" build wrapper with veto: "); if(NS_SUCCEEDED(xpc->WrapNative(jscontext, glob, foo, NS_GET_IID(nsITestXPCFoo2), &wrapper))) { success = JS_FALSE; printf("FAILED\n"); NS_RELEASE(wrapper); } else { printf("passed\n"); } */ sm->SetMode(MySecMan::OK_ALL); printf(" build wrapper no veto: "); nsIXPConnectJSObjectHolder* holder; if(NS_SUCCEEDED(xpc->WrapNative(jscontext, glob, foo, NS_GET_IID(nsITestXPCFoo2), &holder))) { printf("passed\n"); JSObject* obj; if(NS_SUCCEEDED(holder->GetJSObject(&obj))) { rval = OBJECT_TO_JSVAL(obj); JSAutoRequest ar(jscontext); JS_SetProperty(jscontext, glob, "foo", &rval); } NS_RELEASE(holder); } else { success = JS_FALSE; printf("FAILED\n"); } EvaluateScript(jscontext, glob, sm, MySecMan::OK_ALL, " getService no veto: ", "try{Components.classes['@mozilla.org/js/xpc/XPConnect;1'].getService(); print('passed');}catch(e){failed = true; print('FAILED');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::VETO_ALL, " getService with veto: ", "try{Components.classes['@mozilla.org/js/xpc/XPConnect;1'].getService(); failed = true; print('FAILED');}catch(e){print('passed');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::OK_ALL, " createInstance no veto: ", "try{Components.classes['@mozilla.org/js/xpc/ID;1'].createInstance(Components.interfaces.nsIJSID); print('passed');}catch(e){failed = true; print('FAILED');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::VETO_ALL, " getService with veto: ", "try{Components.classes['@mozilla.org/js/xpc/ID;1'].createInstance(Components.interfaces.nsIJSID); failed = true; print('FAILED');}catch(e){print('passed');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::OK_ALL, " call method no veto: ", "try{foo.Test2(); print(' : passed');}catch(e){failed = true; print(' : FAILED');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::VETO_ALL, " call method with veto: ", "try{foo.Test2(); failed = true; print(' : FAILED');}catch(e){print(' : passed');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::OK_ALL, " get attribute no veto: ", "try{foo.Foo; print(' : passed');}catch(e){failed = true; print(' : FAILED');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::VETO_ALL, " get attribute with veto: ", "try{foo.Foo; failed = true; print(' : FAILED');}catch(e){print(' : passed');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::OK_ALL, " set attribute no veto: ", "try{foo.Foo = 0; print(' : passed');}catch(e){failed = true; print(' : FAILED');}", rval); EvaluateScript(jscontext, glob, sm, MySecMan::VETO_ALL, " set attribute with veto: ", "try{foo.Foo = 0; failed = true; print(' : FAILED');}catch(e){print(' : passed');}", rval); sm_test_done: { JSAutoRequest ar(jscontext); success = success && JS_GetProperty(jscontext, glob, "failed", &rval) && JSVAL_TRUE != rval; } printf("SecurityManager tests : %s\n", success ? "passed" : "FAILED"); NS_IF_RELEASE(foo); xpc->SetSecurityManagerForJSContext(jscontext, nsnull, 0); }