ScriptPreprocessor::ScriptPreprocessor(const ScriptSourceCode& preprocessorSourceCode, ScriptController& controller, PageConsole& console) : m_isPreprocessing(false) { v8::TryCatch tryCatch; tryCatch.SetVerbose(true); Vector<ScriptSourceCode> sources; sources.append(preprocessorSourceCode); Vector<ScriptValue> scriptResults; controller.executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorldId, sources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults); if (scriptResults.size() != 1) { console.addMessage(JSMessageSource, ErrorMessageLevel, "ScriptPreprocessor internal error, one ScriptSourceCode must give exactly one result."); return; } ScriptValue preprocessorFunction = scriptResults[0]; if (!preprocessorFunction.isFunction()) { console.addMessage(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function."); return; } m_world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWorldId, DOMWrapperWorld::mainWorldExtensionGroup); v8::Local<v8::Context> context = m_world->context(controller); m_isolate = context->GetIsolate(); m_context.set(m_isolate, context); m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction.v8Value())); }
ScriptPreprocessor::ScriptPreprocessor(const ScriptSourceCode& preprocessorSourceCode, Frame* frame) : m_isolate(V8PerIsolateData::mainThreadIsolate()) , m_isPreprocessing(false) { ASSERT(frame); v8::TryCatch tryCatch; tryCatch.SetVerbose(true); Vector<ScriptSourceCode> sources; sources.append(preprocessorSourceCode); Vector<ScriptValue> scriptResults; frame->script().executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorldId, sources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults); if (scriptResults.size() != 1) { frame->host()->console().addMessage(JSMessageSource, ErrorMessageLevel, "ScriptPreprocessor internal error, one ScriptSourceCode must give exactly one result."); return; } ScriptValue preprocessorFunction = scriptResults[0]; if (!preprocessorFunction.isFunction()) { frame->host()->console().addMessage(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function."); return; } m_world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWorldId, DOMWrapperWorld::mainWorldExtensionGroup); v8::Local<v8::Context> context = toV8Context(m_isolate, frame, m_world.get()); m_context.set(m_isolate, context); m_preprocessorFunction.set(m_isolate, v8::Handle<v8::Function>::Cast(preprocessorFunction.v8Value())); }
ScheduledAction::ScheduledAction(ScriptState* scriptState, const ScriptValue& function, const Vector<ScriptValue>& arguments) : m_scriptState(scriptState) , m_info(scriptState->isolate()) , m_code(String(), KURL(), TextPosition::belowRangePosition()) { ASSERT(function.isFunction()); m_function.set(scriptState->isolate(), v8::Handle<v8::Function>::Cast(function.v8Value())); m_info.ReserveCapacity(arguments.size()); for (const ScriptValue& argument : arguments) m_info.Append(argument.v8Value()); }
PassOwnPtr<ScheduledAction> ScheduledAction::create(ScriptState* scriptState, const ScriptValue& handler, const Vector<ScriptValue>& arguments) { ASSERT(handler.isFunction()); return adoptPtr(new ScheduledAction(scriptState, handler, arguments)); }