static void messageHandlerInMainThread(v8::Handle<v8::Message> message, v8::Handle<v8::Value> data) { ASSERT(isMainThread()); // It's possible that messageHandlerInMainThread() is invoked while we're initializing a window. // In that half-baked situation, we don't have a valid context nor a valid world, // so just return immediately. if (DOMWrapperWorld::windowIsBeingInitialized()) return; v8::Isolate* isolate = v8::Isolate::GetCurrent(); // If called during context initialization, there will be no entered window. LocalDOMWindow* enteredWindow = enteredDOMWindow(isolate); if (!enteredWindow) return; String errorMessage = toCoreString(message->Get()); v8::Handle<v8::StackTrace> stackTrace = message->GetStackTrace(); RefPtr<ScriptCallStack> callStack = nullptr; int scriptId = message->GetScriptOrigin().ScriptID()->Value(); // Currently stack trace is only collected when inspector is open. if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0) { callStack = createScriptCallStack(stackTrace, ScriptCallStack::maxCallStackSizeToCapture, isolate); bool success = false; int topScriptId = callStack->at(0).scriptId().toInt(&success); if (success && topScriptId == scriptId) scriptId = 0; } else { Vector<ScriptCallFrame> callFrames; callStack = ScriptCallStack::create(callFrames); } v8::Handle<v8::Value> resourceName = message->GetScriptOrigin().ResourceName(); bool shouldUseDocumentURL = resourceName.IsEmpty() || !resourceName->IsString(); String resource = shouldUseDocumentURL ? enteredWindow->document()->url() : toCoreString(resourceName.As<v8::String>()); ScriptState* scriptState = ScriptState::current(isolate); RefPtr<ErrorEvent> event = ErrorEvent::create(errorMessage, resource, message->GetLineNumber(), message->GetStartColumn() + 1, &scriptState->world()); if (V8DOMWrapper::isDOMWrapper(data)) { v8::Handle<v8::Object> obj = v8::Handle<v8::Object>::Cast(data); const WrapperTypeInfo* type = toWrapperTypeInfo(obj); if (V8DOMException::wrapperTypeInfo.isSubclass(type)) { DOMException* exception = V8DOMException::toNative(obj); if (exception && !exception->messageForConsole().isEmpty()) event->setUnsanitizedMessage("Uncaught " + exception->toStringForConsole()); } } // This method might be called while we're creating a new context. In this case, we // avoid storing the exception object, as we can't create a wrapper during context creation. // FIXME: Can we even get here during initialization now that we bail out when GetEntered returns an empty handle? LocalFrame* frame = enteredWindow->document()->frame(); if (frame && frame->script().existingWindowProxy(scriptState->world())) { V8ErrorHandler::storeExceptionOnErrorEventWrapper(event.get(), data, scriptState->context()->Global(), isolate); } enteredWindow->document()->reportException(event.release(), scriptId, callStack); }
void SourceLocation::toTracedValue(TracedValue* value, const char* name) const { if (!m_stackTrace || m_stackTrace->isEmpty()) return; value->beginArray(name); value->beginDictionary(); value->setString("functionName", toCoreString(m_stackTrace->topFunctionName())); value->setString("scriptId", toCoreString(m_stackTrace->topScriptId())); value->setString("url", toCoreString(m_stackTrace->topSourceURL())); value->setInteger("lineNumber", m_stackTrace->topLineNumber()); value->setInteger("columnNumber", m_stackTrace->topColumnNumber()); value->endDictionary(); value->endArray(); }
void V8BiquadFilterNode::typeAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { ExceptionState exceptionState(ExceptionState::SetterContext, "type", "BiquadFilterNode", info.Holder(), info.GetIsolate()); BiquadFilterNode* impl = V8BiquadFilterNode::toNative(info.Holder()); if (value->IsNumber()) { uint32_t type = toUInt32(value, exceptionState); if (exceptionState.throwIfNeeded()) return; if (!impl->setType(type)) { exceptionState.throwTypeError("Illegal BiquadFilterNode type"); exceptionState.throwIfNeeded(); } return; } if (value->IsString()) { String type = toCoreString(value.As<v8::String>()); if (type == "lowpass" || type == "highpass" || type == "bandpass" || type == "lowshelf" || type == "highshelf" || type == "peaking" || type == "notch" || type == "allpass") { impl->setType(type); return; } } exceptionState.throwTypeError("Illegal BiquadFilterNode type"); exceptionState.throwIfNeeded(); }
static PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value, Vector<v8::Handle<v8::Array> >& stack, v8::Isolate* isolate) { if (value->IsNumber() && !std::isnan(value->NumberValue())) return IDBKey::createNumber(value->NumberValue()); if (value->IsString()) return IDBKey::createString(toCoreString(value.As<v8::String>())); if (value->IsDate() && !std::isnan(value->NumberValue())) return IDBKey::createDate(value->NumberValue()); if (value->IsArray()) { v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); if (stack.contains(array)) return 0; if (stack.size() >= maximumDepth) return 0; stack.append(array); IDBKey::KeyArray subkeys; uint32_t length = array->Length(); for (uint32_t i = 0; i < length; ++i) { v8::Local<v8::Value> item = array->Get(v8::Int32::New(i, isolate)); RefPtr<IDBKey> subkey = createIDBKeyFromValue(item, stack, isolate); if (!subkey) subkeys.append(IDBKey::createInvalid()); else subkeys.append(subkey); } stack.removeLast(); return IDBKey::createArray(subkeys); } return 0; }
void V8OscillatorNode::typeAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { ExceptionState exceptionState(ExceptionState::SetterContext, "type", "OscillatorNode", info.Holder(), info.GetIsolate()); v8::Handle<v8::Object> holder = info.Holder(); OscillatorNode* imp = V8OscillatorNode::toNative(holder); if (value->IsNumber()) { uint32_t type = toUInt32(value, exceptionState); if (exceptionState.throwIfNeeded()) return; if (!imp->setType(type)) { exceptionState.throwTypeError("Illegal OscillatorNode type"); exceptionState.throwIfNeeded(); } return; } if (value->IsString()) { String type = toCoreString(value.As<v8::String>()); if (type == "sine" || type == "square" || type == "sawtooth" || type == "triangle") { imp->setType(type); return; } } exceptionState.throwTypeError("Illegal OscillatorNode type"); exceptionState.throwIfNeeded(); }
void V8PannerNode::distanceModelAttributeSetterCustom(v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info) { ExceptionState exceptionState(ExceptionState::SetterContext, "distanceModel", "PannerNode", info.Holder(), info.GetIsolate()); PannerNode* impl = V8PannerNode::toNative(info.Holder()); if (value->IsNumber()) { uint32_t model = toUInt32(value, exceptionState); if (exceptionState.throwIfNeeded()) return; if (!impl->setDistanceModel(model)) { exceptionState.throwTypeError("Illegal distanceModel"); exceptionState.throwIfNeeded(); } return; } if (value->IsString()) { String model = toCoreString(value.As<v8::String>()); if (model == "linear" || model == "inverse" || model == "exponential") { impl->setDistanceModel(model); return; } } exceptionState.throwTypeError("Illegal distanceModel"); exceptionState.throwIfNeeded(); }
bool eventListenerHandlerLocation(Document* document, EventListener* listener, String& sourceName, String& scriptId, int& lineNumber) { if (listener->type() != EventListener::JSEventListenerType) return false; v8::HandleScope scope(toIsolate(document)); V8AbstractEventListener* v8Listener = static_cast<V8AbstractEventListener*>(listener); v8::Handle<v8::Context> context = toV8Context(document, v8Listener->world()); v8::Context::Scope contextScope(context); v8::Local<v8::Object> object = v8Listener->getListenerObject(document); if (object.IsEmpty()) return false; v8::Handle<v8::Function> function = eventListenerEffectiveFunction(scope.GetIsolate(), object); if (function.IsEmpty()) return false; v8::Handle<v8::Function> originalFunction = getBoundFunction(function); int scriptIdValue = originalFunction->ScriptId(); scriptId = String::number(scriptIdValue); v8::ScriptOrigin origin = originalFunction->GetScriptOrigin(); if (!origin.ResourceName().IsEmpty() && origin.ResourceName()->IsString()) sourceName = toCoreString(origin.ResourceName().As<v8::String>()); else sourceName = ""; lineNumber = originalFunction->GetScriptLineNumber(); return true; }
ScriptValue WorkerOrWorkletScriptController::evaluate( const String& script, const String& fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) { TRACE_EVENT1("devtools.timeline", "EvaluateScript", "data", InspectorEvaluateScriptEvent::data(nullptr, fileName, scriptStartPosition)); if (!initializeContextIfNeeded()) return ScriptValue(); ScriptState::Scope scope(m_scriptState.get()); if (!m_disableEvalPending.isEmpty()) { m_scriptState->context()->AllowCodeGenerationFromStrings(false); m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings( v8String(m_isolate, m_disableEvalPending)); m_disableEvalPending = String(); } v8::TryCatch block(m_isolate); v8::Local<v8::Script> compiledScript; v8::MaybeLocal<v8::Value> maybeResult; if (v8Call(V8ScriptRunner::compileScript( script, fileName, String(), scriptStartPosition, m_isolate, cacheHandler, SharableCrossOrigin, v8CacheOptions), compiledScript, block)) maybeResult = V8ScriptRunner::runCompiledScript(m_isolate, compiledScript, m_globalScope); if (!block.CanContinue()) { forbidExecution(); return ScriptValue(); } if (block.HasCaught()) { v8::Local<v8::Message> message = block.Message(); m_executionState->hadException = true; m_executionState->errorMessage = toCoreString(message->Get()); m_executionState->m_location = SourceLocation::fromMessage( m_isolate, message, m_scriptState->getExecutionContext()); m_executionState->exception = ScriptValue(m_scriptState.get(), block.Exception()); block.Reset(); } else { m_executionState->hadException = false; } v8::Local<v8::Value> result; if (!maybeResult.ToLocal(&result) || result->IsUndefined()) return ScriptValue(); return ScriptValue(m_scriptState.get(), result); }
// static std::unique_ptr<SourceLocation> SourceLocation::createFromNonEmptyV8StackTrace( std::unique_ptr<v8_inspector::V8StackTrace> stackTrace, int scriptId) { // Retrieve the data before passing the ownership to SourceLocation. String url = toCoreString(stackTrace->topSourceURL()); unsigned lineNumber = stackTrace->topLineNumber(); unsigned columnNumber = stackTrace->topColumnNumber(); return wrapUnique(new SourceLocation(url, lineNumber, columnNumber, std::move(stackTrace), scriptId)); }
static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame) { StringBuilder stringBuilder; stringBuilder.appendNumber(frame->GetScriptId()); String scriptId = stringBuilder.toString(); String sourceName; v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); if (!sourceNameValue.IsEmpty()) sourceName = toCoreString(sourceNameValue); String functionName; v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); if (!functionNameValue.IsEmpty()) functionName = toCoreString(functionNameValue); int sourceLineNumber = frame->GetLineNumber(); int sourceColumn = frame->GetColumn(); return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber, sourceColumn); }
void V8XMLHttpRequest::responseAttributeGetterCustom( const v8::FunctionCallbackInfo<v8::Value>& info) { XMLHttpRequest* xmlHttpRequest = V8XMLHttpRequest::toImpl(info.Holder()); ExceptionState exceptionState(info.GetIsolate(), ExceptionState::GetterContext, "XMLHttpRequest", "response"); switch (xmlHttpRequest->getResponseTypeCode()) { case XMLHttpRequest::ResponseTypeDefault: case XMLHttpRequest::ResponseTypeText: responseTextAttributeGetterCustom(info); return; case XMLHttpRequest::ResponseTypeJSON: { v8::Isolate* isolate = info.GetIsolate(); ScriptString jsonSource = xmlHttpRequest->responseJSONSource(); if (jsonSource.isEmpty()) { v8SetReturnValue(info, v8::Null(isolate)); return; } // Catch syntax error. Swallows an exception (when thrown) as the // spec says. https://xhr.spec.whatwg.org/#response-body v8::Local<v8::Value> json = fromJSONString( isolate, toCoreString(jsonSource.v8Value()), exceptionState); if (exceptionState.hadException()) { exceptionState.clearException(); v8SetReturnValue(info, v8::Null(isolate)); } else { v8SetReturnValue(info, json); } return; } case XMLHttpRequest::ResponseTypeDocument: { Document* document = xmlHttpRequest->responseXML(exceptionState); v8SetReturnValueFast(info, document, xmlHttpRequest); return; } case XMLHttpRequest::ResponseTypeBlob: { Blob* blob = xmlHttpRequest->responseBlob(); v8SetReturnValueFast(info, blob, xmlHttpRequest); return; } case XMLHttpRequest::ResponseTypeArrayBuffer: { DOMArrayBuffer* arrayBuffer = xmlHttpRequest->responseArrayBuffer(); v8SetReturnValueFast(info, arrayBuffer, xmlHttpRequest); return; } } }
bool ScriptValue::getString(String& result) const { if (hasNoValue()) return false; v8::HandleScope handleScope(m_isolate); v8::Handle<v8::Value> string = v8Value(); if (string.IsEmpty() || !string->IsString()) return false; result = toCoreString(string.As<v8::String>()); return true; }
static PassRefPtr<JSONValue> v8ToJSONValue(v8::Handle<v8::Value> value, int maxDepth, v8::Isolate* isolate) { if (value.IsEmpty()) { ASSERT_NOT_REACHED(); return 0; } if (!maxDepth) return 0; maxDepth--; if (value->IsNull() || value->IsUndefined()) return JSONValue::null(); if (value->IsBoolean()) return JSONBasicValue::create(value->BooleanValue()); if (value->IsNumber()) return JSONBasicValue::create(value->NumberValue()); if (value->IsString()) return JSONString::create(toCoreString(value.As<v8::String>())); if (value->IsArray()) { v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); RefPtr<JSONArray> inspectorArray = JSONArray::create(); uint32_t length = array->Length(); for (uint32_t i = 0; i < length; i++) { v8::Local<v8::Value> value = array->Get(v8::Int32::New(isolate, i)); RefPtr<JSONValue> element = v8ToJSONValue(value, maxDepth, isolate); if (!element) return 0; inspectorArray->pushValue(element); } return inspectorArray; } if (value->IsObject()) { RefPtr<JSONObject> jsonObject = JSONObject::create(); v8::Handle<v8::Object> object = v8::Handle<v8::Object>::Cast(value); v8::Local<v8::Array> propertyNames = object->GetPropertyNames(); uint32_t length = propertyNames->Length(); for (uint32_t i = 0; i < length; i++) { v8::Local<v8::Value> name = propertyNames->Get(v8::Int32::New(isolate, i)); // FIXME(yurys): v8::Object should support GetOwnPropertyNames if (name->IsString() && !object->HasRealNamedProperty(v8::Handle<v8::String>::Cast(name))) continue; RefPtr<JSONValue> propertyValue = v8ToJSONValue(object->Get(name), maxDepth, isolate); if (!propertyValue) return 0; V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<WithNullCheck>, nameString, name, 0); jsonObject->setValue(nameString, propertyValue); } return jsonObject; } ASSERT_NOT_REACHED(); return 0; }
bool ScriptValue::toString(String& result) const { if (isEmpty()) return false; ScriptState::Scope scope(m_scriptState.get()); v8::Local<v8::Value> string = v8Value(); if (string.IsEmpty() || !string->IsString()) return false; result = toCoreString(v8::Local<v8::String>::Cast(string)); return true; }
void MainThreadDebugger::consoleAPIMessage( int contextGroupId, v8_inspector::V8ConsoleAPIType type, const v8_inspector::StringView& message, const v8_inspector::StringView& url, unsigned lineNumber, unsigned columnNumber, v8_inspector::V8StackTrace* stackTrace) { LocalFrame* frame = WeakIdentifierMap<LocalFrame>::lookup(contextGroupId); if (!frame) return; if (type == v8_inspector::V8ConsoleAPIType::kClear && frame->host()) frame->host()->consoleMessageStorage().clear(); // TODO(dgozman): we can save a copy of message and url here by making // FrameConsole work with StringView. std::unique_ptr<SourceLocation> location = SourceLocation::create(toCoreString(url), lineNumber, columnNumber, stackTrace ? stackTrace->clone() : nullptr, 0); frame->console().reportMessageToClient(ConsoleAPIMessageSource, consoleAPITypeToMessageLevel(type), toCoreString(message), location.get()); }
ScriptValue WorkerScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, CachedMetadataHandler* cacheHandler, V8CacheOptions v8CacheOptions) { if (!initializeContextIfNeeded()) return ScriptValue(); ScriptState::Scope scope(m_scriptState.get()); if (!m_disableEvalPending.isEmpty()) { m_scriptState->context()->AllowCodeGenerationFromStrings(false); m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8String(isolate(), m_disableEvalPending)); m_disableEvalPending = String(); } v8::TryCatch block(isolate()); v8::Local<v8::Script> compiledScript; v8::MaybeLocal<v8::Value> maybeResult; if (v8Call(V8ScriptRunner::compileScript(script, fileName, String(), scriptStartPosition, isolate(), cacheHandler, SharableCrossOrigin, v8CacheOptions), compiledScript, block)) maybeResult = V8ScriptRunner::runCompiledScript(isolate(), compiledScript, m_workerGlobalScope); if (!block.CanContinue()) { forbidExecution(); return ScriptValue(); } if (block.HasCaught()) { v8::Local<v8::Message> message = block.Message(); m_executionState->hadException = true; m_executionState->errorMessage = toCoreString(message->Get()); if (v8Call(message->GetLineNumber(m_scriptState->context()), m_executionState->lineNumber) && v8Call(message->GetStartColumn(m_scriptState->context()), m_executionState->columnNumber)) { ++m_executionState->columnNumber; } else { m_executionState->lineNumber = 0; m_executionState->columnNumber = 0; } TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin().ResourceName(), ScriptValue()); m_executionState->sourceURL = sourceURL; m_executionState->exception = ScriptValue(m_scriptState.get(), block.Exception()); block.Reset(); } else { m_executionState->hadException = false; } v8::Local<v8::Value> result; if (!maybeResult.ToLocal(&result) || result->IsUndefined()) return ScriptValue(); return ScriptValue(m_scriptState.get(), result); }
bool ScriptArguments::getFirstArgumentAsString(String& result, bool checkForNullOrUndefined) { if (!argumentCount()) return false; const ScriptValue& value = argumentAt(0); ScriptState::Scope scope(m_scriptState.get()); if (checkForNullOrUndefined && (value.isNull() || value.isUndefined())) return false; // We intentionally ignore an exception that can be thrown in ToString(). v8::TryCatch block; v8::Handle<v8::String> string = value.v8Value()->ToString(); result = string.IsEmpty() ? String() : toCoreString(string); return true; }
static void setTimeoutOrInterval(const v8::FunctionCallbackInfo<v8::Value>& info, bool singleShot) { WorkerGlobalScope* workerGlobalScope = V8WorkerGlobalScope::toNative(info.Holder()); ASSERT(workerGlobalScope); int argumentCount = info.Length(); if (argumentCount < 1) return; v8::Handle<v8::Value> function = info[0]; WorkerScriptController* script = workerGlobalScope->script(); if (!script) return; ScriptState* scriptState = ScriptState::current(info.GetIsolate()); OwnPtr<ScheduledAction> action; if (function->IsString()) { if (ContentSecurityPolicy* policy = workerGlobalScope->contentSecurityPolicy()) { if (!policy->allowEval()) { v8SetReturnValue(info, 0); return; } } action = adoptPtr(new ScheduledAction(scriptState, toCoreString(function.As<v8::String>()), workerGlobalScope->url(), info.GetIsolate())); } else if (function->IsFunction()) { size_t paramCount = argumentCount >= 2 ? argumentCount - 2 : 0; OwnPtr<v8::Local<v8::Value>[]> params; if (paramCount > 0) { params = adoptArrayPtr(new v8::Local<v8::Value>[paramCount]); for (size_t i = 0; i < paramCount; ++i) params[i] = info[i+2]; } // ScheduledAction takes ownership of actual params and releases them in its destructor. action = adoptPtr(new ScheduledAction(scriptState, v8::Handle<v8::Function>::Cast(function), paramCount, params.get(), info.GetIsolate())); } else return; int32_t timeout = argumentCount >= 2 ? info[1]->Int32Value() : 0; int timerId; if (singleShot) timerId = DOMWindowTimers::setTimeout(*workerGlobalScope, action.release(), timeout); else timerId = DOMWindowTimers::setInterval(*workerGlobalScope, action.release(), timeout); v8SetReturnValue(info, timerId); }
ScriptValue WorkerScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, WorkerGlobalScopeExecutionState* state) { v8::HandleScope handleScope(isolate()); if (!initializeContextIfNeeded()) return ScriptValue(); v8::Handle<v8::Context> context = m_contextHolder->context(); if (!m_disableEvalPending.isEmpty()) { context->AllowCodeGenerationFromStrings(false); context->SetErrorMessageForCodeGenerationFromStrings(v8String(isolate(), m_disableEvalPending)); m_disableEvalPending = String(); } v8::Context::Scope scope(context); v8::TryCatch block; v8::Handle<v8::String> scriptString = v8String(isolate(), script); v8::Handle<v8::Script> compiledScript = V8ScriptRunner::compileScript(scriptString, fileName, scriptStartPosition, 0, isolate()); v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(compiledScript, &m_workerGlobalScope, isolate()); if (!block.CanContinue()) { m_workerGlobalScope.script()->forbidExecution(); return ScriptValue(); } if (block.HasCaught()) { v8::Local<v8::Message> message = block.Message(); state->hadException = true; state->errorMessage = toCoreString(message->Get()); state->lineNumber = message->GetLineNumber(); state->columnNumber = message->GetStartColumn() + 1; V8TRYCATCH_FOR_V8STRINGRESOURCE_RETURN(V8StringResource<>, sourceURL, message->GetScriptResourceName(), ScriptValue()); state->sourceURL = sourceURL; state->exception = ScriptValue(block.Exception(), isolate()); block.Reset(); } else state->hadException = false; if (result.IsEmpty() || result->IsUndefined()) return ScriptValue(); return ScriptValue(result, isolate()); }
ScriptValue WorkerScriptController::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition) { if (!initializeContextIfNeeded()) return ScriptValue(); ScriptState::Scope scope(m_scriptState.get()); if (!m_disableEvalPending.isEmpty()) { m_scriptState->context()->AllowCodeGenerationFromStrings(false); m_scriptState->context()->SetErrorMessageForCodeGenerationFromStrings(v8String(m_isolate, m_disableEvalPending)); m_disableEvalPending = String(); } v8::TryCatch block; v8::Handle<v8::String> scriptString = v8String(m_isolate, script); v8::Handle<v8::Script> compiledScript = V8ScriptRunner::compileScript(scriptString, fileName, scriptStartPosition, 0, 0, m_isolate); v8::Local<v8::Value> result = V8ScriptRunner::runCompiledScript(m_isolate, compiledScript, &m_workerGlobalScope); if (!block.CanContinue()) { m_workerGlobalScope.script()->forbidExecution(); return ScriptValue(); } if (block.HasCaught()) { v8::Local<v8::Message> message = block.Message(); m_globalScopeExecutionState->hadException = true; m_globalScopeExecutionState->errorMessage = toCoreString(message->Get()); m_globalScopeExecutionState->lineNumber = message->GetLineNumber(); m_globalScopeExecutionState->columnNumber = message->GetStartColumn() + 1; TOSTRING_DEFAULT(V8StringResource<>, sourceURL, message->GetScriptOrigin().ResourceName(), ScriptValue()); m_globalScopeExecutionState->sourceURL = sourceURL; m_globalScopeExecutionState->exception = ScriptValue(m_scriptState.get(), block.Exception()); block.Reset(); } else { m_globalScopeExecutionState->hadException = false; } if (result.IsEmpty() || result->IsUndefined()) return ScriptValue(); return ScriptValue(m_scriptState.get(), result); }
static IDBKey* createIDBKeyFromValue(v8::Isolate* isolate, v8::Handle<v8::Value> value, Vector<v8::Handle<v8::Array> >& stack, bool allowExperimentalTypes = false) { if (value->IsNumber() && !std::isnan(value->NumberValue())) return IDBKey::createNumber(value->NumberValue()); if (value->IsString()) return IDBKey::createString(toCoreString(value.As<v8::String>())); if (value->IsDate() && !std::isnan(value->NumberValue())) return IDBKey::createDate(value->NumberValue()); if (value->IsUint8Array() && (allowExperimentalTypes || RuntimeEnabledFeatures::indexedDBExperimentalEnabled())) { // Per discussion in https://www.w3.org/Bugs/Public/show_bug.cgi?id=23332 the // input type is constrained to Uint8Array to match the output type. ArrayBufferView* view = blink::V8ArrayBufferView::toImpl(value->ToObject()); const char* start = static_cast<const char*>(view->baseAddress()); size_t length = view->byteLength(); return IDBKey::createBinary(SharedBuffer::create(start, length)); } if (value->IsArray()) { v8::Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(value); if (stack.contains(array)) return 0; if (stack.size() >= maximumDepth) return 0; stack.append(array); IDBKey::KeyArray subkeys; uint32_t length = array->Length(); for (uint32_t i = 0; i < length; ++i) { v8::Local<v8::Value> item = array->Get(v8::Int32::New(isolate, i)); IDBKey* subkey = createIDBKeyFromValue(isolate, item, stack, allowExperimentalTypes); if (!subkey) subkeys.append(IDBKey::createInvalid()); else subkeys.append(subkey); } stack.removeLast(); return IDBKey::createArray(subkeys); } return 0; }
static ScriptCallFrame toScriptCallFrame(v8::Handle<v8::StackFrame> frame) { StringBuilder stringBuilder; stringBuilder.appendNumber(frame->GetScriptId()); String scriptId = stringBuilder.toString(); String sourceName; v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); if (!sourceNameValue.IsEmpty()) { int length = sourceNameValue->Length(); sourceName = StringTraits<String>::fromV8String<V8StringOneByteTrait>(sourceNameValue, length); } String functionName; v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); if (!functionNameValue.IsEmpty()) functionName = toCoreString(functionNameValue); int sourceLineNumber = frame->GetLineNumber(); int sourceColumn = frame->GetColumn(); return ScriptCallFrame(functionName, scriptId, sourceName, sourceLineNumber, sourceColumn); }
PassRefPtr<ScriptProfile> ScriptProfiler::stop(const String& title) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::CpuProfiler* profiler = isolate->GetCpuProfiler(); if (!profiler) return nullptr; v8::HandleScope handleScope(isolate); v8::CpuProfile* profile = profiler->StopProfiling(v8String(isolate, title)); if (!profile) return nullptr; String profileTitle = toCoreString(profile->GetTitle()); double idleTime = 0.0; ProfileNameIdleTimeMap* profileNameIdleTimeMap = ScriptProfiler::currentProfileNameIdleTimeMap(); ProfileNameIdleTimeMap::iterator profileIdleTime = profileNameIdleTimeMap->find(profileTitle); if (profileIdleTime != profileNameIdleTimeMap->end()) { idleTime = profileIdleTime->value * 1000.0; profileNameIdleTimeMap->remove(profileIdleTime); } return ScriptProfile::create(profile, idleTime); }
String DictionaryTest::stringFromIterable(ExecutionContext* executionContext, Dictionary iterable, ExceptionState& exceptionState) const { StringBuilder result; DictionaryIterator iterator = iterable.getIterator(executionContext); if (!iterator.isValid()) return emptyString(); bool firstLoop = true; while (iterator.next(executionContext, exceptionState)) { if (exceptionState.hadException()) return emptyString(); if (firstLoop) firstLoop = false; else result.append(","); v8::Local<v8::Value> value; if (v8Call(iterator.value(), value)) result.append(toCoreString(value->ToString())); } return result.toString(); }
String SourceLocation::toString() const { if (!m_stackTrace) return String(); return toCoreString(m_stackTrace->toString()); }
String toCoreString(std::unique_ptr<v8_inspector::StringBuffer> buffer) { if (!buffer) return String(); return toCoreString(buffer->string()); }
String HeapProfileXDK::getRetentions() const { v8::HandleScope handleScope(m_isolate); return toCoreString(v8AtomicString(m_isolate, m_event->getRetentions())); }
static String extractResourceName(v8::Local<v8::Message> message, const Document* document) { v8::Local<v8::Value> resourceName = message->GetScriptOrigin().ResourceName(); bool shouldUseDocumentURL = document && (resourceName.IsEmpty() || !resourceName->IsString()); return shouldUseDocumentURL ? document->url() : toCoreString(resourceName.As<v8::String>()); }