void ScriptDebugServer::compileScript(ScriptState* state, const String& expression, const String& sourceURL, String* scriptId, String* exceptionMessage) { v8::HandleScope handleScope; v8::Handle<v8::Context> context = state->context(); if (context.IsEmpty()) return; v8::Context::Scope contextScope(context); v8::Local<v8::String> code = v8ExternalString(expression); v8::TryCatch tryCatch; v8::ScriptOrigin origin(v8ExternalString(sourceURL), v8::Integer::New(0), v8::Integer::New(0)); v8::Handle<v8::Script> script = v8::Script::New(code, &origin); if (tryCatch.HasCaught()) { v8::Local<v8::Message> message = tryCatch.Message(); if (!message.IsEmpty()) *exceptionMessage = toWebCoreStringWithNullOrUndefinedCheck(message->Get()); return; } if (script.IsEmpty()) return; *scriptId = toWebCoreStringWithNullOrUndefinedCheck(script->Id()); m_compiledScripts.set(*scriptId, adoptPtr(new OwnHandle<v8::Script>(script))); }
static v8::Handle<v8::Value> handlePostMessageCallback(const v8::Arguments& args) { DOMWindow* window = V8DOMWindow::toNative(args.Holder()); DOMWindow* source = V8Proxy::retrieveFrameForCallingContext()->domWindow(); ASSERT(source->frame()); bool didThrow = false; RefPtr<SerializedScriptValue> message = SerializedScriptValue::create(args[0], didThrow); if (didThrow) return v8::Undefined(); MessagePortArray portArray; String targetOrigin; // This function has variable arguments and can either be: // postMessage(message, port, targetOrigin); // or // postMessage(message, targetOrigin); v8::TryCatch tryCatch; if (args.Length() > 2) { if (!getMessagePortArray(args[1], portArray)) return v8::Undefined(); targetOrigin = toWebCoreStringWithNullOrUndefinedCheck(args[2]); } else { targetOrigin = toWebCoreStringWithNullOrUndefinedCheck(args[1]); } if (tryCatch.HasCaught()) return v8::Undefined(); ExceptionCode ec = 0; window->postMessage(message.release(), &portArray, targetOrigin, source, ec); return throwError(ec); }
void ScriptDebugServer::runScript(ScriptState* state, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionMessage) { v8::HandleScope handleScope; OwnHandle<v8::Script>* scriptOwnHandle = m_compiledScripts.get(scriptId); v8::Local<v8::Script> script = v8::Local<v8::Script>::New(scriptOwnHandle->get()); m_compiledScripts.remove(scriptId); if (script.IsEmpty()) return; v8::Handle<v8::Context> context = state->context(); if (context.IsEmpty()) return; v8::Context::Scope contextScope(context); v8::Local<v8::Value> value; v8::TryCatch tryCatch; { V8RecursionScope recursionScope(state->scriptExecutionContext()); value = script->Run(); } *wasThrown = false; if (tryCatch.HasCaught()) { *wasThrown = true; *result = ScriptValue(tryCatch.Exception()); v8::Local<v8::Message> message = tryCatch.Message(); if (!message.IsEmpty()) *exceptionMessage = toWebCoreStringWithNullOrUndefinedCheck(message->Get()); } else *result = ScriptValue(value); }
void ScriptDebugServer::dispatchDidParseSource(ScriptDebugListener* listener, v8::Handle<v8::Object> object) { String sourceID = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("id"))); ScriptDebugListener::Script script; script.url = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("name"))); script.source = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("source"))); script.sourceMappingURL = toWebCoreStringWithNullOrUndefinedCheck(object->Get(v8::String::New("sourceMappingURL"))); script.startLine = object->Get(v8::String::New("startLine"))->ToInteger()->Value(); script.startColumn = object->Get(v8::String::New("startColumn"))->ToInteger()->Value(); script.endLine = object->Get(v8::String::New("endLine"))->ToInteger()->Value(); script.endColumn = object->Get(v8::String::New("endColumn"))->ToInteger()->Value(); script.isContentScript = object->Get(v8::String::New("isContentScript"))->ToBoolean()->Value(); listener->didParseSource(sourceID, script); }
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; }
String JavaScriptCallFrame::functionName() const { v8::HandleScope handleScope; v8::Context::Scope contextScope(m_debuggerContext.get()); v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("functionName")); return toWebCoreStringWithNullOrUndefinedCheck(result); }
v8::Handle<v8::Value> V8DOMWindow::openCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.open()"); DOMWindow* impl = V8DOMWindow::toNative(args.Holder()); V8BindingState* state = V8BindingState::Only(); DOMWindow* activeWindow = state->activeWindow(); DOMWindow* firstWindow = state->firstWindow(); // FIXME: Handle exceptions properly. String urlString = toWebCoreStringWithNullOrUndefinedCheck(args[0]); AtomicString frameName = (args[1]->IsUndefined() || args[1]->IsNull()) ? "_blank" : AtomicString(toWebCoreString(args[1])); String windowFeaturesString = toWebCoreStringWithNullOrUndefinedCheck(args[2]); RefPtr<DOMWindow> openedWindow = impl->open(urlString, frameName, windowFeaturesString, activeWindow, firstWindow); if (!openedWindow) return v8::Undefined(); return toV8(openedWindow.release()); }
v8::Handle<v8::Value> V8DOMWindow::showModalDialogCallback(const v8::Arguments& args) { INC_STATS("DOM.DOMWindow.showModalDialog()"); DOMWindow* impl = V8DOMWindow::toNative(args.Holder()); V8BindingState* state = V8BindingState::Only(); DOMWindow* activeWindow = state->activeWindow(); DOMWindow* firstWindow = state->firstWindow(); // FIXME: Handle exceptions properly. String urlString = toWebCoreStringWithNullOrUndefinedCheck(args[0]); String dialogFeaturesString = toWebCoreStringWithNullOrUndefinedCheck(args[2]); DialogHandler handler(args[1]); impl->showModalDialog(urlString, dialogFeaturesString, activeWindow, firstWindow, setUpDialog, &handler); return handler.returnValue(); }
v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args) { RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(toWebCoreString(args[0])); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); if (tryCatch.HasCaught()) return v8::Undefined(); String url; if (args.Length() > 2) { url = toWebCoreStringWithNullOrUndefinedCheck(args[2]); if (tryCatch.HasCaught()) return v8::Undefined(); } ExceptionCode ec = 0; History* history = V8DOMWrapper::convertToNativeObject<History>(V8ClassIndex::HISTORY, args.Holder()); history->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec); return throwError(ec); }
v8::Handle<v8::Value> V8History::replaceStateCallback(const v8::Arguments& args) { bool didThrow = false; RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], didThrow); if (didThrow) return v8::Undefined(); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); if (tryCatch.HasCaught()) return v8::Undefined(); String url; if (args.Length() > 2) { url = toWebCoreStringWithNullOrUndefinedCheck(args[2]); if (tryCatch.HasCaught()) return v8::Undefined(); } ExceptionCode ec = 0; History* history = V8History::toNative(args.Holder()); history->stateObjectAdded(historyState.release(), title, url, History::StateObjectReplace, ec); return throwError(ec); }
v8::Handle<v8::Value> V8History::pushStateCallback(const v8::Arguments& args) { bool didThrow = false; RefPtr<SerializedScriptValue> historyState = SerializedScriptValue::create(args[0], 0, 0, didThrow, args.GetIsolate()); if (didThrow) return v8::Undefined(); v8::TryCatch tryCatch; String title = toWebCoreStringWithNullOrUndefinedCheck(args[1]); if (tryCatch.HasCaught()) return v8::Undefined(); String url; if (args.Length() > 2) { url = toWebCoreStringWithNullOrUndefinedCheck(args[2]); if (tryCatch.HasCaught()) return v8::Undefined(); } ExceptionCode ec = 0; History* history = V8History::toNative(args.Holder()); history->stateObjectAdded(historyState.release(), title, url, History::StateObjectPush, ec); args.Holder()->DeleteHiddenValue(V8HiddenPropertyName::state()); return setDOMException(ec, args.GetIsolate()); }