String v8ValueToWebCoreString(v8::Handle<v8::Value> object)
{
    if (object->IsString())
        return v8StringToWebCoreString(v8::Handle<v8::String>::Cast(object), Externalize, PlainStringType);

    if (object->IsInt32()) {
        int value = object->Int32Value();
        // Most numbers used are <= 100. Even if they aren't used there's very little in using the space.
        const int kLowNumbers = 100;
        static AtomicString lowNumbers[kLowNumbers + 1];
        String webCoreString;
        if (0 <= value && value <= kLowNumbers) {
            webCoreString = lowNumbers[value];
            if (!webCoreString) {
                AtomicString valueString = AtomicString(String::number(value));
                lowNumbers[value] = valueString;
                webCoreString = valueString;
            }
        } else
            webCoreString = String::number(value);
        return webCoreString;
    }

    v8::TryCatch block;
    v8::Handle<v8::String> v8String = object->ToString();
    // Handle the case where an exception is thrown as part of invoking toString on the object.
    if (block.HasCaught()) {
        throwError(block.Exception());
        return StringImpl::empty();
    }
    return v8StringToWebCoreString(v8String, DoNotExternalize, PlainStringType);
}
AtomicString v8StringToAtomicWebCoreString(v8::Handle<v8::String> v8String)
{
    WebCoreStringResource* stringResource = WebCoreStringResource::toStringResource(v8String);
    if (!stringResource) {
        // If this string hasn't been externalized, we force it now.
        String plain = v8StringToWebCoreString(v8String, Externalize, AtomicStringType);
        // If the string is empty there's no room to cache an atomic
        // string so we bail out.
        if (plain.isEmpty())
            return plain;
        stringResource = WebCoreStringResource::toStringResource(v8String);
        ASSERT(stringResource != NULL);
    }
    return stringResource->atomicString();
}
Beispiel #3
0
String ScriptDebugServer::setBreakpoint(const String& sourceID, const ScriptBreakpoint& scriptBreakpoint, int* actualLineNumber, int* actualColumnNumber)
{
    v8::HandleScope scope;
    v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
    v8::Context::Scope contextScope(debuggerContext);

    v8::Local<v8::Object> args = v8::Object::New();
    args->Set(v8::String::New("sourceID"), v8String(sourceID));
    args->Set(v8::String::New("lineNumber"), v8::Integer::New(scriptBreakpoint.lineNumber));
    args->Set(v8::String::New("columnNumber"), v8::Integer::New(scriptBreakpoint.columnNumber));
    args->Set(v8::String::New("condition"), v8String(scriptBreakpoint.condition));

    v8::Handle<v8::Function> setBreakpointFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("setBreakpoint")));
    v8::Handle<v8::Value> breakpointId = v8::Debug::Call(setBreakpointFunction, args);
    if (!breakpointId->IsString())
        return "";
    *actualLineNumber = args->Get(v8::String::New("lineNumber"))->Int32Value();
    *actualColumnNumber = args->Get(v8::String::New("columnNumber"))->Int32Value();
    return v8StringToWebCoreString(breakpointId->ToString());
}
String ScriptStringImpl::toString() const
{
    return v8StringToWebCoreString(m_handle.get());
}