ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExceptions) { ScriptState::Scope scope(m_scriptState.get()); v8::TryCatch tryCatch; tryCatch.SetVerbose(reportExceptions); v8::Handle<v8::Object> thisObject = m_thisObject.v8Object(); v8::Local<v8::Value> value = thisObject->Get(v8String(m_scriptState->isolate(), m_name)); if (tryCatch.HasCaught()) { hadException = true; return ScriptObject(); } ASSERT(value->IsFunction()); v8::Local<v8::Function> constructor = v8::Local<v8::Function>::Cast(value); OwnPtr<v8::Handle<v8::Value>[]> info = adoptArrayPtr(new v8::Handle<v8::Value>[m_arguments.size()]); for (size_t i = 0; i < m_arguments.size(); ++i) info[i] = m_arguments[i].v8Value(); v8::Local<v8::Object> result = V8ObjectConstructor::newInstance(m_scriptState->isolate(), constructor, m_arguments.size(), info.get()); if (tryCatch.HasCaught()) { hadException = true; return ScriptObject(); } return ScriptObject(m_scriptState.get(), result); }
ScriptObject InjectedScriptManager::createInjectedScript(const String& source, ScriptState* scriptState, int id) { JSLockHolder lock(scriptState); SourceCode sourceCode = makeSource(source); JSDOMGlobalObject* globalObject = jsCast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); JSValue globalThisValue = scriptState->globalThisValue(); JSValue evaluationException; JSValue evaluationReturnValue; if (isMainThread()) evaluationReturnValue = JSMainThreadExecState::evaluate(scriptState, sourceCode, globalThisValue, &evaluationException); else { JSC::JSLockHolder lock(scriptState); evaluationReturnValue = JSC::evaluate(scriptState, sourceCode, globalThisValue, &evaluationException); } if (evaluationException) return ScriptObject(); JSValue functionValue = evaluationReturnValue; CallData callData; CallType callType = getCallData(functionValue, callData); if (callType == CallTypeNone) return ScriptObject(); MarkedArgumentBuffer args; args.append(toJS(scriptState, globalObject, m_injectedScriptHost.get())); args.append(globalThisValue); args.append(jsNumber(id)); JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args); if (result.isObject()) return ScriptObject(scriptState, result.getObject()); return ScriptObject(); }
ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned id) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); if (!profiler) return ScriptObject(); // As ids are unique, it doesn't matter which HeapSnapshot owns HeapGraphNode. // We need to find first HeapSnapshot containing a node with the specified id. const v8::HeapGraphNode* node = 0; for (int i = 0, l = profiler->GetSnapshotCount(); i < l; ++i) { const v8::HeapSnapshot* snapshot = profiler->GetHeapSnapshot(i); node = snapshot->GetNodeById(id); if (node) break; } if (!node) return ScriptObject(); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> value = node->GetHeapValue(); if (!value->IsObject()) return ScriptObject(); v8::Handle<v8::Object> object = value.As<v8::Object>(); ScriptState* scriptState = ScriptState::forContext(object->CreationContext()); return ScriptObject(scriptState, object); }
ScriptObject InjectedScriptManager::createInjectedScript(const String& scriptSource, ScriptState* inspectedScriptState, int id) { v8::Isolate* isolate = inspectedScriptState->isolate(); v8::HandleScope handleScope(isolate); v8::Local<v8::Context> inspectedContext = inspectedScriptState->context(); v8::Context::Scope contextScope(inspectedContext); // Call custom code to create InjectedScripHost wrapper specific for the context // instead of calling toV8() that would create the // wrapper in the current context. // FIXME: make it possible to use generic bindings factory for InjectedScriptHost. v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(m_injectedScriptHost.get(), inspectedContext->GetIsolate()); if (scriptHostWrapper.IsEmpty()) return ScriptObject(); // Inject javascript into the context. The compiled script is supposed to evaluate into // a single anonymous function(it's anonymous to avoid cluttering the global object with // inspector's stuff) the function is called a few lines below with InjectedScriptHost wrapper, // injected script id and explicit reference to the inspected global object. The function is expected // to create and configure InjectedScript instance that is going to be used by the inspector. v8::Local<v8::Value> value = V8ScriptRunner::compileAndRunInternalScript(v8String(isolate, scriptSource), isolate); ASSERT(!value.IsEmpty()); ASSERT(value->IsFunction()); v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); v8::Handle<v8::Value> info[] = { scriptHostWrapper, windowGlobal, v8::Number::New(inspectedContext->GetIsolate(), id) }; v8::Local<v8::Value> injectedScriptValue = V8ScriptRunner::callInternalFunction(v8::Local<v8::Function>::Cast(value), windowGlobal, WTF_ARRAY_LENGTH(info), info, inspectedContext->GetIsolate()); return ScriptObject(inspectedScriptState, v8::Handle<v8::Object>::Cast(injectedScriptValue)); }
ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExceptions) { JSObject* thisObject = m_thisObject.jsObject(); JSLock lock(SilenceAssertionsOnly); JSObject* constructor = asObject(thisObject->get(m_exec, Identifier(m_exec, stringToUString(m_name)))); if (m_exec->hadException()) { if (reportExceptions) reportException(m_exec, m_exec->exception()); hadException = true; return ScriptObject(); } ConstructData constructData; ConstructType constructType = constructor->getConstructData(constructData); if (constructType == ConstructTypeNone) return ScriptObject(); JSValue result = JSC::construct(m_exec, constructor, constructType, constructData, m_arguments); if (m_exec->hadException()) { if (reportExceptions) reportException(m_exec, m_exec->exception()); hadException = true; return ScriptObject(); } return ScriptObject(m_exec, asObject(result)); }
ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned id) { // As ids are unique, it doesn't matter which HeapSnapshot owns HeapGraphNode. // We need to find first HeapSnapshot containing a node with the specified id. const v8::HeapGraphNode* node = 0; for (int i = 0, l = v8::HeapProfiler::GetSnapshotsCount(); i < l; ++i) { const v8::HeapSnapshot* snapshot = v8::HeapProfiler::GetSnapshot(i); node = snapshot->GetNodeById(id); if (node) break; } if (!node) return ScriptObject(); v8::HandleScope scope; v8::Handle<v8::Value> value = node->GetHeapValue(); if (!value->IsObject()) return ScriptObject(); v8::Handle<v8::Object> object = value.As<v8::Object>(); if (object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount) { v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIndex); // Skip wrapper boilerplates which are like regular wrappers but don't have // native object. if (!wrapper.IsEmpty() && wrapper->IsUndefined()) return ScriptObject(); } ScriptState* scriptState = ScriptState::forContext(object->CreationContext()); return ScriptObject(scriptState, object); }
ScriptObject ScriptFunctionCall::construct(bool& hadException, bool reportExceptions) { ScriptScope scope(m_scriptState, reportExceptions); v8::Local<v8::Object> thisObject = m_thisObject.v8Object(); v8::Local<v8::Value> value = thisObject->Get(v8String(m_name)); if (!scope.success()) { hadException = true; return ScriptObject(); } ASSERT(value->IsFunction()); v8::Local<v8::Function> constructor(v8::Function::Cast(*value)); OwnArrayPtr<v8::Handle<v8::Value> > args(new v8::Handle<v8::Value>[m_arguments.size()]); for (size_t i = 0; i < m_arguments.size(); ++i) args[i] = m_arguments[i].v8Value(); v8::Local<v8::Object> result = SafeAllocation::newInstance(constructor, m_arguments.size(), args.get()); if (!scope.success()) { hadException = true; return ScriptObject(); } return ScriptObject(m_scriptState, result); }
ScriptObject InjectedScriptHost::createInjectedScript(const String& source, ScriptState* scriptState, long id) { SourceCode sourceCode = makeSource(stringToUString(source)); JSLock lock(SilenceAssertionsOnly); JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); JSValue globalThisValue = scriptState->globalThisValue(); Completion comp = JSMainThreadExecState::evaluate(scriptState, globalObject->globalScopeChain(), sourceCode, globalThisValue); if (comp.complType() != JSC::Normal && comp.complType() != JSC::ReturnValue) return ScriptObject(); JSValue functionValue = comp.value(); CallData callData; CallType callType = functionValue.getCallData(callData); if (callType == CallTypeNone) return ScriptObject(); MarkedArgumentBuffer args; args.append(toJS(scriptState, globalObject, this)); args.append(globalThisValue); args.append(jsNumber(scriptState, id)); args.append(jsString(scriptState, String("JSC"))); JSValue result = JSC::call(scriptState, functionValue, callType, callData, globalThisValue, args); if (result.isObject()) return ScriptObject(scriptState, result.getObject()); return ScriptObject(); }
ScriptObject InjectedScriptCanvasModule::callWrapContextFunction(const String& functionName, const ScriptObject& context) { ScriptFunctionCall function(injectedScriptObject(), functionName); function.appendArgument(context); bool hadException = false; ScriptValue resultValue = callFunctionWithEvalEnabled(function, hadException); if (hadException || resultValue.hasNoValue() || !resultValue.isObject()) { ASSERT_NOT_REACHED(); return ScriptObject(); } return ScriptObject(context.scriptState(), resultValue); }
/// <summary>Generates the ID and reverse lookup collections from the string library</summary> /// <param name="data">Feedback data</param> /// <returns>Number of objects generated</returns> /// <exception cref="Logic::InvalidValueException">Invalid sector string ID</exception> UINT ScriptObjectLibrary::Populate(WorkerData* data) { ObjectCollection unmangled(GetSpecialCases()); // Extract all script objects from library [this loop correctly enforces string precedence] for (auto& file : StringLib.Files) for (auto& page : file) for (auto& str : page) if (str.IsScriptObject()) unmangled.Add( ScriptObject(str.ID, (KnownPage)page.ID, str.ResolvedText, str.Version) ); // Generate reverse lookup collection for (const auto& pair : unmangled) { const ScriptObject& obj = pair.second; // Special Case: Exclude Add,Substract,Minus from lookup if (!obj.CanLookup()) continue; // Attempt to insert if (!Lookup.Add(obj)) { // Extract conflict ScriptObject conflict = Lookup.Find(obj.Text); Lookup.Remove(obj.Text); // Feedback Console << Cons::Red << "Conflict: " << Cons::Reset << obj.Text << " : " << Cons::Yellow << obj.Ident << Cons::White << L" vs " << Cons::Yellow << conflict.Ident << Cons::White << "..."; // Mangle them if (!MangleConflicts(obj, conflict)) { // Failed: Feedback VString err(L"Conflicting script objects '%s' detected: %s and %s", obj.Text.c_str(), obj.Ident.c_str(), conflict.Ident.c_str()); data->SendFeedback(ProgressType::Error, 2, err); Console << Cons::Error << L"Failed to resolve" << ENDL; } } } // Populate ID collection from lookup to preserve name mangling for (const ScriptObject& obj : *this) Objects.Add(obj); // SpecialCase: Add old [THIS] to ID collection so older scripts can be parsed Objects.Add(ScriptObject(0, KnownPage::CONSTANTS, L"THIS", GameVersion::Threat)); // Return count return Objects.size(); }
InjectedScript InjectedScriptManager::injectedScriptFor(ScriptState* inspectedScriptState) { v8::HandleScope handleScope; v8::Local<v8::Context> context = inspectedScriptState->context(); v8::Context::Scope contextScope(context); v8::Local<v8::Object> global = context->Global(); // Skip proxy object. The proxy object will survive page navigation while we need // an object whose lifetime consides with that of the inspected context. global = v8::Local<v8::Object>::Cast(global->GetPrototype()); v8::Handle<v8::String> key = V8HiddenPropertyName::devtoolsInjectedScript(); v8::Local<v8::Value> val = global->GetHiddenValue(key); if (!val.IsEmpty() && val->IsObject()) return InjectedScript(ScriptObject(inspectedScriptState, v8::Local<v8::Object>::Cast(val)), m_inspectedStateAccessCheck); if (!m_inspectedStateAccessCheck(inspectedScriptState)) return InjectedScript(); pair<long, ScriptObject> injectedScript = injectScript(injectedScriptSource(), inspectedScriptState); InjectedScript result(injectedScript.second, m_inspectedStateAccessCheck); m_idToInjectedScript.set(injectedScript.first, result); global->SetHiddenValue(key, injectedScript.second.v8Object()); return result; }
bool ScriptDebugServer::setScriptSource(const String& sourceID, const String& newContent, bool preview, String* error, ScriptValue* newCallFrames, ScriptObject* result) { ensureDebuggerScriptCompiled(); v8::HandleScope scope; OwnPtr<v8::Context::Scope> contextScope; if (!isPaused()) contextScope = adoptPtr(new v8::Context::Scope(v8::Debug::GetDebugContext())); v8::Handle<v8::Value> argv[] = { v8String(sourceID), v8String(newContent), v8Boolean(preview) }; v8::TryCatch tryCatch; tryCatch.SetVerbose(false); v8::Local<v8::Value> v8result = callDebuggerMethod("setScriptSource", 3, argv); if (tryCatch.HasCaught()) { v8::Local<v8::Message> message = tryCatch.Message(); if (!message.IsEmpty()) *error = toWebCoreStringWithNullOrUndefinedCheck(message->Get()); else *error = "Unknown error."; return false; } ASSERT(!v8result.IsEmpty()); if (v8result->IsObject()) *result = ScriptObject(ScriptState::current(), v8result->ToObject()); // Call stack may have changed after if the edited function was on the stack. if (!preview && isPaused()) *newCallFrames = currentCallFrame(); return true; }
void PromiseTracker::didCreatePromise(const ScriptObject& promise) { ASSERT(isEnabled()); double timestamp = currentTimeMS(); m_promiseDataMap.set(promise, adoptRef(new PromiseData(promise, ScriptObject(), ScriptValue(), V8PromiseCustom::Pending, timestamp))); }
void *LuaScript::registerCFunc(void *context, const char *name, void *func) { DECL_STATE(L, context); auto func_wrapper = [](lua_State *L) -> int { ScriptContext::CFunc func = (ScriptContext::CFunc)lua_touserdata(L, lua_upvalueindex(1)); int argc = lua_gettop(L); Vector<ScriptObject> args(argc); args.resize(argc); for(int i = argc; i; i--) { void *ref = OBJECT(luaL_ref(L, LUA_REGISTRYINDEX)); args[i-1] = ScriptObject(L, ref); } ScriptObject ret = func(args, kwargs_stub); if(!ret.isBound()) return 0; PUSH_REF(L, ret.object); return 1; }; lua_pushlightuserdata(L, func); lua_pushcclosure(L, func_wrapper, 1); if(name) { lua_pushvalue(L, -1); lua_setglobal(L, name); } return OBJECT(luaL_ref(L, LUA_REGISTRYINDEX)); }
void WebDevToolsAgentImpl::setInspectorFrontendProxyToInspectorController() { v8::HandleScope scope; ScriptState* state = ScriptState::forContext( v8::Local<v8::Context>::New(m_utilityContext)); InspectorController* ic = inspectorController(); ic->setFrontend(new InspectorFrontend( ScriptObject(state, m_utilityContext->Global()))); }
bool getQuarantinedScriptObject(Database* database, ScriptObject& quarantinedObject) { ASSERT(database); // FIXME: Implement when Database V8 bindings are enabled ASSERT_NOT_REACHED(); quarantinedObject = ScriptObject(); return false; }
bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject) { ASSERT(frame); ASSERT(storage); #if ENABLE(DOM_STORAGE) v8::HandleScope handleScope; v8::Local<v8::Context> context = V8Proxy::context(frame); // FIXME: What if context.IsEmpty()? v8::Context::Scope scope(context); v8::Handle<v8::Value> v8Storage = V8DOMWrapper::convertToV8Object(V8ClassIndex::STORAGE, storage); quarantinedObject = ScriptObject(frame->script()->state(), v8::Local<v8::Object>(v8::Object::Cast(*v8Storage))); #else ASSERT_NOT_REACHED(); quarantinedObject = ScriptObject(); #endif return true; }
bool getQuarantinedScriptObject(Frame* frame, Storage* storage, ScriptObject& quarantinedObject) { ASSERT(frame); ASSERT(storage); // FIXME: Implement when DOM Storage V8 bindings are enabled ASSERT_NOT_REACHED(); quarantinedObject = ScriptObject(); return true; }
// Set a |promise|'s state and result that correspond to the state. // |promise| must be a Promise instance. void setStateForPromise(v8::Handle<v8::Object> promise, V8PromiseCustom::PromiseState state, v8::Handle<v8::Value> value, v8::Isolate* isolate) { ASSERT(!value.IsEmpty()); ASSERT(state == V8PromiseCustom::Pending || state == V8PromiseCustom::Fulfilled || state == V8PromiseCustom::Rejected || state == V8PromiseCustom::Following); v8::Local<v8::Object> internal = V8PromiseCustom::getInternal(promise); internal->SetInternalField(V8PromiseCustom::InternalStateIndex, v8::Integer::New(isolate, state)); internal->SetInternalField(V8PromiseCustom::InternalResultIndex, value); ExecutionContext* context = currentExecutionContext(isolate); if (InspectorInstrumentation::isPromiseTrackerEnabled(context)) InspectorInstrumentation::didUpdatePromiseState(context, ScriptObject(ScriptState::forContext(isolate->GetCurrentContext()), promise), state, ScriptValue(value, isolate)); }
bool ScriptGlobalObject::get(ScriptState* scriptState, const char* name, ScriptObject& value) { JSLock lock(SilenceAssertionsOnly); JSValue jsValue = scriptState->lexicalGlobalObject()->get(scriptState, Identifier(scriptState, name)); if (!jsValue) return false; if (!jsValue.isObject()) return false; value = ScriptObject(scriptState, asObject(jsValue)); return true; }
bool ScriptGlobalObject::get(ScriptState* scriptState, const char* name, ScriptObject& value) { ScriptScope scope(scriptState); v8::Local<v8::Value> v8Value = scope.global()->Get(v8::String::New(name)); if (v8Value.IsEmpty()) return false; if (!v8Value->IsObject()) return false; value = ScriptObject(v8::Handle<v8::Object>(v8::Object::Cast(*v8Value))); return true; }
bool getQuarantinedScriptObject(DOMWindow* domWindow, ScriptObject& quarantinedObject) { ASSERT(domWindow); v8::HandleScope handleScope; v8::Local<v8::Context> context = V8Proxy::GetContext(domWindow->frame()); v8::Context::Scope scope(context); v8::Handle<v8::Value> v8DomWindow = V8Proxy::ToV8Object(V8ClassIndex::DOMWINDOW, domWindow); quarantinedObject = ScriptObject(v8::Local<v8::Object>(v8::Object::Cast(*v8DomWindow))); return true; }
bool getQuarantinedScriptObject(Node* node, ScriptObject& quarantinedObject) { ASSERT(node); v8::HandleScope handleScope; v8::Local<v8::Context> context = V8Proxy::GetContext(node->document()->page()->mainFrame()); v8::Context::Scope scope(context); v8::Handle<v8::Value> v8Node = V8Proxy::NodeToV8Object(node); quarantinedObject = ScriptObject(v8::Local<v8::Object>(v8::Object::Cast(*v8Node))); return true; }
ScriptObject ScriptProfiler::objectByHeapObjectId(unsigned id) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::HeapProfiler* profiler = isolate->GetHeapProfiler(); v8::HandleScope handleScope(isolate); v8::Handle<v8::Value> value = profiler->FindObjectById(id); if (value.IsEmpty() || !value->IsObject()) return ScriptObject(); v8::Handle<v8::Object> object = value.As<v8::Object>(); if (object->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount) { v8::Handle<v8::Value> wrapper = object->GetInternalField(v8DOMWrapperObjectIndex); // Skip wrapper boilerplates which are like regular wrappers but don't have // native object. if (!wrapper.IsEmpty() && wrapper->IsUndefined()) return ScriptObject(); } ScriptState* scriptState = ScriptState::forContext(object->CreationContext()); return ScriptObject(scriptState, object); }
bool ScriptGlobalObject::get(JSC::ExecState* scriptState, const char* name, ScriptObject& value) { JSLockHolder lock(scriptState); JSValue jsValue = scriptState->lexicalGlobalObject()->get(scriptState, Identifier(scriptState, name)); if (!jsValue) return false; if (!jsValue.isObject()) return false; value = ScriptObject(scriptState, asObject(jsValue)); return true; }
ScriptObject InjectedScriptManager::createInjectedScript(const String& scriptSource, ScriptState* inspectedScriptState, long id) { v8::HandleScope scope; v8::Local<v8::Context> inspectedContext = inspectedScriptState->context(); v8::Context::Scope contextScope(inspectedContext); // Call custom code to create InjectedScripHost wrapper specific for the context // instead of calling toV8() that would create the // wrapper in the current context. // FIXME: make it possible to use generic bindings factory for InjectedScriptHost. v8::Local<v8::Object> scriptHostWrapper = createInjectedScriptHostV8Wrapper(m_injectedScriptHost.get()); if (scriptHostWrapper.IsEmpty()) return ScriptObject(); v8::Local<v8::Object> windowGlobal = inspectedContext->Global(); // Inject javascript into the context. The compiled script is supposed to evaluate into // a single anonymous function(it's anonymous to avoid cluttering the global object with // inspector's stuff) the function is called a few lines below with InjectedScriptHost wrapper, // injected script id and explicit reference to the inspected global object. The function is expected // to create and configure InjectedScript instance that is going to be used by the inspector. v8::Local<v8::Script> script = v8::Script::Compile(v8String(scriptSource)); V8RecursionScope::MicrotaskSuppression recursionScope; v8::Local<v8::Value> v = script->Run(); ASSERT(!v.IsEmpty()); ASSERT(v->IsFunction()); v8::Handle<v8::Value> args[] = { scriptHostWrapper, windowGlobal, v8::Number::New(id), }; v8::Local<v8::Value> injectedScriptValue = v8::Function::Cast(*v)->Call(windowGlobal, 3, args); v8::Local<v8::Object> injectedScript(v8::Object::Cast(*injectedScriptValue)); return ScriptObject(inspectedScriptState, injectedScript); }
InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* scriptState) { JSLock lock(SilenceAssertionsOnly); JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); JSObject* injectedScript = globalObject->injectedScript(); if (injectedScript) return InjectedScript(ScriptObject(scriptState, injectedScript)); ASSERT(!m_injectedScriptSource.isEmpty()); pair<long, ScriptObject> injectedScriptObject = injectScript(m_injectedScriptSource, scriptState); globalObject->setInjectedScript(injectedScriptObject.second.jsObject()); InjectedScript result(injectedScriptObject.second); m_idToInjectedScript.set(injectedScriptObject.first, result); return result; }
bool getQuarantinedScriptObject(DOMWindow* domWindow, ScriptObject& quarantinedObject) { ASSERT(domWindow); v8::HandleScope handleScope; Frame* frame = domWindow->frame(); // FIXME: What if frame is null? v8::Local<v8::Context> context = V8Proxy::context(frame); // FIXME: What if context.IsEmpty()? v8::Context::Scope scope(context); v8::Handle<v8::Value> v8DomWindow = V8DOMWrapper::convertToV8Object(V8ClassIndex::DOMWINDOW, domWindow); quarantinedObject = ScriptObject(frame->script()->state(), v8::Local<v8::Object>(v8::Object::Cast(*v8DomWindow))); return true; }
InjectedScript InjectedScriptHost::injectedScriptFor(ScriptState* scriptState) { JSLock lock(SilenceAssertionsOnly); JSDOMGlobalObject* globalObject = static_cast<JSDOMGlobalObject*>(scriptState->lexicalGlobalObject()); JSObject* injectedScript = globalObject->injectedScript(); if (injectedScript) return InjectedScript(ScriptObject(scriptState, injectedScript)); ASSERT(!m_injectedScriptSource.isEmpty()); ScriptObject injectedScriptObject = createInjectedScript(m_injectedScriptSource, this, scriptState, m_nextInjectedScriptId); globalObject->setInjectedScript(injectedScriptObject.jsObject()); InjectedScript result(injectedScriptObject); m_idToInjectedScript.set(m_nextInjectedScriptId, result); m_nextInjectedScriptId++; return result; }
bool getQuarantinedScriptObject(Node* node, ScriptObject& quarantinedObject) { ASSERT(node); v8::HandleScope handleScope; // FIXME: What if document() is null? // FIXME: Why are we grabbing the mainFrame? Frame* frame = node->document()->page()->mainFrame(); v8::Local<v8::Context> context = V8Proxy::context(frame); // FIXME: What if context.IsEmpty()? v8::Context::Scope scope(context); v8::Handle<v8::Value> v8Node = V8DOMWrapper::convertNodeToV8Object(node); quarantinedObject = ScriptObject(frame->script()->state(), v8::Local<v8::Object>(v8::Object::Cast(*v8Node))); return true; }