コード例 #1
0
PassRefPtr<InspectorValue> ScriptValue::toInspectorValue(ScriptState* scriptState) const
{
    v8::HandleScope handleScope;
    // v8::Object::GetPropertyNames() expects current context to be not null.
    v8::Context::Scope contextScope(scriptState->context());
    return v8ToInspectorValue(v8ValueRaw(), InspectorValue::maxDepth);
}
コード例 #2
0
ファイル: Script.cpp プロジェクト: caivega/canvas-cpp
 bool Script::runString(std::string const& code, std::string const& filename)
 {
    v8::HandleScope scope;
    v8::Context::Scope contextScope(m_context);
    v8::TryCatch tryCatch;
    
    // Create a v8 string to hold the source
    v8::Handle<v8::String> source = v8::String::New(code.c_str(), code.size());
    
    // Compile the script
    v8::Handle<v8::Script> script = v8::Script::Compile(source, v8::String::New(filename.c_str()));
    if (script.IsEmpty())
    {
       v8::String::Utf8Value error(tryCatch.Exception());
       v8::Handle<v8::Message> message = tryCatch.Message();
       
       std::cerr << "+----" << std::endl;
       std::cerr << "| Error in " << filename.c_str() << ":" << *error << std::endl;
       std::cerr << "| (" << message->GetLineNumber() << "):" << *v8::String::Utf8Value(message->GetSourceLine()) << std::endl;
       std::cerr << "+----" << std::endl;
       return false;
    }
    
    // Finally we run the script
    v8::Handle<v8::Value> result = script->Run();
    if (result.IsEmpty())
    {
       v8::String::Utf8Value error(tryCatch.Exception());
       std::cerr << "Script Error: " << *error << std::endl;
       return false;
    }
       
    return true;
 }
コード例 #3
0
ファイル: Runtime.cpp プロジェクト: mustaphamond/jessip
void Runtime::runMainScript()
{
   v8::HandleScope scope(v8::Isolate::GetCurrent());
   v8::Handle<v8::Context> context = v8::Context::New(
         v8::Isolate::GetCurrent());
   v8::Context::Scope contextScope(context);
   m_sip = new JsSIPObject(m_sipFactory);
   m_sip->createObjectInstance(context->Global(), "sip");
   v8::TryCatch tryCatch;
   std::string mainScript;

   loadMainScript(mainScript);
   v8::Handle<v8::Script> script = v8::Script::Compile(
         v8::String::New(mainScript.c_str()),
         v8::String::New(m_scriptFileName.c_str()));
   if (script.IsEmpty())
   {
      throw Exception(JsProxyBase::toString(tryCatch.Exception()).c_str());
   }
   v8::Handle<v8::Value> result = script->Run();
   if (result.IsEmpty())
   {
      // TODO: add log
      v8::String::Utf8Value stackTrace(tryCatch.StackTrace());
      if (stackTrace.length() > 0)
      {
         throw Exception(*stackTrace);
      }
      throw Exception(JsProxyBase::toString(tryCatch.Exception()).c_str());
   }
}
コード例 #4
0
ファイル: Script.cpp プロジェクト: caivega/canvas-cpp
   v8::Local<v8::Value> Script::getObject(std::string const& name)
   {
      v8::HandleScope scope;
      v8::Context::Scope contextScope(m_context);

      return scope.Close(m_context->Global()->Get(v8::String::New(name.c_str())));
   }
コード例 #5
0
void WorkerScriptDebugServer::addListener(ScriptDebugListener* listener, WorkerContext* workerContext)
{
    v8::HandleScope scope;
    v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
    v8::Context::Scope contextScope(debuggerContext);

    if (!m_listenersMap.size()) {
        // FIXME: synchronize access to this code.
        ensureDebuggerScriptCompiled();
        ASSERT(!m_debuggerScript.get()->IsUndefined());
        v8::Debug::SetDebugEventListener2(&WorkerScriptDebugServer::v8DebugEventCallback, v8::External::New(this));
    }
    m_listenersMap.set(workerContext, listener);
    
    WorkerContextExecutionProxy* proxy = workerContext->script()->proxy();
    if (!proxy)
        return;
    v8::Handle<v8::Context> context = proxy->context();

    v8::Handle<v8::Function> getScriptsFunction = v8::Local<v8::Function>::Cast(m_debuggerScript.get()->Get(v8::String::New("getWorkerScripts")));
    v8::Handle<v8::Value> argv[] = { v8::Handle<v8::Value>() };
    v8::Handle<v8::Value> value = getScriptsFunction->Call(m_debuggerScript.get(), 0, argv);
    if (value.IsEmpty())
        return;
    ASSERT(!value->IsUndefined() && value->IsArray());
    v8::Handle<v8::Array> scriptsArray = v8::Handle<v8::Array>::Cast(value);
    for (unsigned i = 0; i < scriptsArray->Length(); ++i)
        dispatchDidParseSource(listener, v8::Handle<v8::Object>::Cast(scriptsArray->Get(v8::Integer::New(i))));
}
コード例 #6
0
ファイル: context.cpp プロジェクト: hanigamal/PHP-JS
/**
 *  Assign a variable to the javascript context
 *
 *  @param  params  array of parameters:
 *                  -   string  name of property to assign  required
 *                  -   mixed   property value to assign    required
 *                  -   integer property attributes         optional
 *
 *  The property attributes can be one of the following values
 *
 *  - ReadOnly
 *  - DontEnum
 *  - DontDelete
 *
 *  If not specified, the property will be writable, enumerable and
 *  deletable.
 */
void Context::assign(Php::Parameters &params)
{
    // create a local "scope" and "enter" our context
    v8::HandleScope         scope(isolate());
    v8::Context::Scope      contextScope(_context);

    // retrieve the global object from the context
    v8::Local<v8::Object>   global(_context->Global());

    // the attribute for the newly assigned property
    v8::PropertyAttribute   attribute(v8::None);

    // if an attribute was given, assign it
    if (params.size() > 2)
    {
        // check the attribute that was selected
        switch ((int16_t)params[2])
        {
            case v8::None:          attribute = v8::None;       break;
            case v8::ReadOnly:      attribute = v8::ReadOnly;   break;
            case v8::DontDelete:    attribute = v8::DontDelete; break;
            case v8::DontEnum:      attribute = v8::DontEnum;   break;
        }
    }

    // and store the value
    global->ForceSet(value(params[0]), value(params[1]), attribute);
}
コード例 #7
0
ファイル: Path2D.cpp プロジェクト: Adenilson/skia
// Install the constructor in the global scope so Path2Ds can be constructed
// in JS.
void Path2D::AddToGlobal(Global* global) {
    gGlobal = global;

    // Create a stack-allocated handle scope.
    HandleScope handleScope(gGlobal->getIsolate());

    Handle<Context> context = gGlobal->getContext();

    // Enter the scope so all operations take place in the scope.
    Context::Scope contextScope(context);

    Local<FunctionTemplate> constructor = FunctionTemplate::New(
            gGlobal->getIsolate(), Path2D::ConstructPath);
    constructor->InstanceTemplate()->SetInternalFieldCount(1);

    ADD_METHOD("closePath", ClosePath);
    ADD_METHOD("moveTo", MoveTo);
    ADD_METHOD("lineTo", LineTo);
    ADD_METHOD("quadraticCurveTo", QuadraticCurveTo);
    ADD_METHOD("bezierCurveTo", BezierCurveTo);
    ADD_METHOD("arc", Arc);
    ADD_METHOD("rect", Rect);
    ADD_METHOD("oval", Oval);
    ADD_METHOD("conicTo", ConicTo);

    context->Global()->Set(String::NewFromUtf8(
            gGlobal->getIsolate(), "Path2D"), constructor->GetFunction());
}
コード例 #8
0
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);
}
コード例 #9
0
ファイル: JSONParser.cpp プロジェクト: Silex/rtags
bool JSONParser::parse(const String& json)
{
    v8::Isolate* isolate = v8::Isolate::New();
    const v8::Isolate::Scope isolateScope(isolate);
    v8::HandleScope handleScope;

    v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();
#ifdef V8_NEW_CONTEXT_TAKES_ISOLATE
    v8::Handle<v8::Context> context = v8::Context::New(isolate, 0, globalTemplate);
#else
    v8::Handle<v8::Context> context = v8::Context::New(0, globalTemplate);
#endif
    v8::Context::Scope contextScope(context);

    v8::Handle<v8::Object> global = context->Global();

    v8::Handle<v8::Object> JSON = global->Get(v8::String::New("JSON"))->ToObject();
    v8::Handle<v8::Function> JSON_parse = v8::Handle<v8::Function>::Cast(JSON->Get(v8::String::New("parse")));

    v8::Handle<v8::Value> data = v8::String::New(json.constData(), json.size());
    v8::Handle<v8::Value> value = JSON_parse->Call(JSON, 1, &data);

    mRoot = v8ValueToValue(value);
    //isolate->Dispose();
    return isValid();
}
コード例 #10
0
ファイル: ScriptEventListener.cpp プロジェクト: kublaj/blink
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;
}
コード例 #11
0
ファイル: AnimationTest.cpp プロジェクト: wangshijun/Blink
TEST_F(AnimationAnimationTest, TimingInputDirection)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    v8::Context::Scope contextScope(context);

    Timing timing;
    Timing::PlaybackDirection defaultPlaybackDirection = Timing::PlaybackDirectionNormal;
    EXPECT_EQ(defaultPlaybackDirection, timing.direction);

    applyTimingInputString(timing, isolate, "direction", "normal");
    EXPECT_EQ(Timing::PlaybackDirectionNormal, timing.direction);
    timing.direction = defaultPlaybackDirection;

    applyTimingInputString(timing, isolate, "direction", "reverse");
    EXPECT_EQ(Timing::PlaybackDirectionReverse, timing.direction);
    timing.direction = defaultPlaybackDirection;

    applyTimingInputString(timing, isolate, "direction", "alternate");
    EXPECT_EQ(Timing::PlaybackDirectionAlternate, timing.direction);
    timing.direction = defaultPlaybackDirection;

    applyTimingInputString(timing, isolate, "direction", "alternate-reverse");
    EXPECT_EQ(Timing::PlaybackDirectionAlternateReverse, timing.direction);
    timing.direction = defaultPlaybackDirection;

    applyTimingInputString(timing, isolate, "direction", "rubbish");
    EXPECT_EQ(defaultPlaybackDirection, timing.direction);
    timing.direction = defaultPlaybackDirection;

    applyTimingInputNumber(timing, isolate, "direction", 2);
    EXPECT_EQ(defaultPlaybackDirection, timing.direction);
    timing.direction = defaultPlaybackDirection;
}
コード例 #12
0
ファイル: AnimationTest.cpp プロジェクト: wangshijun/Blink
TEST_F(AnimationAnimationTest, TimingInputPlaybackRate)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    v8::Context::Scope contextScope(context);

    Timing timing;
    EXPECT_EQ(1, timing.playbackRate);

    applyTimingInputNumber(timing, isolate, "playbackRate", 2.1);
    EXPECT_EQ(2.1, timing.playbackRate);
    timing.playbackRate = 1;

    applyTimingInputNumber(timing, isolate, "playbackRate", -1);
    EXPECT_EQ(-1, timing.playbackRate);
    timing.playbackRate = 1;

    applyTimingInputString(timing, isolate, "playbackRate", "Infinity");
    EXPECT_EQ(1, timing.playbackRate);
    timing.playbackRate = 1;

    applyTimingInputString(timing, isolate, "playbackRate", "-Infinity");
    EXPECT_EQ(1, timing.playbackRate);
    timing.playbackRate = 1;

    applyTimingInputString(timing, isolate, "playbackRate", "NaN");
    EXPECT_EQ(1, timing.playbackRate);
    timing.playbackRate = 1;

    applyTimingInputString(timing, isolate, "playbackRate", "rubbish");
    EXPECT_EQ(1, timing.playbackRate);
    timing.playbackRate = 1;
}
コード例 #13
0
ファイル: AnimationTest.cpp プロジェクト: wangshijun/Blink
TEST_F(AnimationAnimationTest, TimingInputIterationCount)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    v8::Context::Scope contextScope(context);

    Timing timing;
    EXPECT_EQ(1, timing.iterationCount);

    applyTimingInputNumber(timing, isolate, "iterations", 2.1);
    EXPECT_EQ(2.1, timing.iterationCount);
    timing.iterationCount = 1;

    applyTimingInputNumber(timing, isolate, "iterations", -1);
    EXPECT_EQ(0, timing.iterationCount);
    timing.iterationCount = 1;

    applyTimingInputString(timing, isolate, "iterations", "Infinity");
    EXPECT_TRUE(std::isinf(timing.iterationCount) && (timing.iterationCount > 0));
    timing.iterationCount = 1;

    applyTimingInputString(timing, isolate, "iterations", "-Infinity");
    EXPECT_EQ(0, timing.iterationCount);
    timing.iterationCount = 1;

    applyTimingInputString(timing, isolate, "iterations", "NaN");
    EXPECT_EQ(1, timing.iterationCount);
    timing.iterationCount = 1;

    applyTimingInputString(timing, isolate, "iterations", "rubbish");
    EXPECT_EQ(1, timing.iterationCount);
    timing.iterationCount = 1;
}
コード例 #14
0
void V8DOMWindowShell::updateDocumentProperty()
{
    if (!m_world->isMainWorld())
        return;

    v8::HandleScope handleScope;
    // FIXME: Should we use a new Local handle here?
    v8::Context::Scope contextScope(m_context.get());

    v8::Handle<v8::Value> documentWrapper = toV8(m_frame->document(), v8::Handle<v8::Object>(), m_context.get()->GetIsolate());
    ASSERT(documentWrapper == m_document.get() || m_document.isEmpty());
    if (m_document.isEmpty())
        updateDocumentWrapper(v8::Handle<v8::Object>::Cast(documentWrapper));
    checkDocumentWrapper(m_document.get(), m_frame->document());

    // If instantiation of the document wrapper fails, clear the cache
    // and let the DOMWindow accessor handle access to the document.
    if (documentWrapper.IsEmpty()) {
        clearDocumentProperty();
        return;
    }
    ASSERT(documentWrapper->IsObject());
    m_context->Global()->ForceSet(v8::String::NewSymbol("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));

    // We also stash a reference to the document on the inner global object so that
    // DOMWindow objects we obtain from JavaScript references are guaranteed to have
    // live Document objects.
    toInnerGlobalObject(m_context.get())->SetHiddenValue(V8HiddenPropertyName::document(), documentWrapper);
}
コード例 #15
0
ファイル: context.cpp プロジェクト: hanigamal/PHP-JS
/**
 *  Parse a piece of javascript code
 *
 *  @param  params  array with one parameter: the code to execute
 *  @return Php::Value
 */
Php::Value Context::evaluate(Php::Parameters &params)
{
    // create a handle, so that all variables fall "out of scope"
    v8::HandleScope         scope(isolate());

    // enter the compilation/execution scope
    v8::Context::Scope      contextScope(_context);

    // catch any errors that occur while either compiling or running the script
    v8::TryCatch            catcher;

    // compile the code into a script
    v8::Local<v8::String>   source(v8::String::NewFromUtf8(isolate(), params[0]));
    v8::Local<v8::Script>   script(v8::Script::Compile(source));

    // execute the script
    v8::Local<v8::Value>    result(script->Run());

    // did we catch an exception?
    if (catcher.HasCaught())
    {
        // retrieve the message describing the problem
        v8::Local<v8::Message>  message(catcher.Message());
        v8::Local<v8::String>   description(message->Get());

        // convert the description to utf so we can dump it
        v8::String::Utf8Value   string(description);

        // pass this exception on to PHP userspace
        throw Php::Exception(std::string(*string, string.length()));
    }

    // return the result
    return value(result);
}
コード例 #16
0
ファイル: V8Proxy.cpp プロジェクト: 325116067/semc-qsd8x50
// Create the utility context for holding JavaScript functions used internally
// which are not visible to JavaScript executing on the page.
void V8Proxy::createUtilityContext()
{
    ASSERT(m_utilityContext.IsEmpty());

    v8::HandleScope scope;
    v8::Handle<v8::ObjectTemplate> globalTemplate = v8::ObjectTemplate::New();
    m_utilityContext = v8::Context::New(0, globalTemplate);
    v8::Context::Scope contextScope(m_utilityContext);

    // Compile JavaScript function for retrieving the source line of the top
    // JavaScript stack frame.
    DEFINE_STATIC_LOCAL(const char*, frameSourceLineSource,
        ("function frameSourceLine(exec_state) {"
        "  return exec_state.frame(0).sourceLine();"
        "}"));
    v8::Script::Compile(v8::String::New(frameSourceLineSource))->Run();

    // Compile JavaScript function for retrieving the source name of the top
    // JavaScript stack frame.
    DEFINE_STATIC_LOCAL(const char*, frameSourceNameSource,
        ("function frameSourceName(exec_state) {"
        "  var frame = exec_state.frame(0);"
        "  if (frame.func().resolved() && "
        "      frame.func().script() && "
        "      frame.func().script().name()) {"
        "    return frame.func().script().name();"
        "  }"
        "}"));
    v8::Script::Compile(v8::String::New(frameSourceNameSource))->Run();
}
コード例 #17
0
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);
}
コード例 #18
0
ファイル: V8Proxy.cpp プロジェクト: jackiekaon/owb-mirror
void V8Proxy::clearForNavigation()
{
    disconnectEventListeners();
    if (!context().IsEmpty()) {
        v8::HandleScope handle;
        clearDocumentWrapper();

        v8::Context::Scope contextScope(context());

        // Clear the document wrapper cache before turning on access checks on
        // the old DOMWindow wrapper. This way, access to the document wrapper
        // will be protected by the security checks on the DOMWindow wrapper.
        clearDocumentWrapperCache();

        // Turn on access check on the old DOMWindow wrapper.
        v8::Handle<v8::Object> wrapper = V8DOMWrapper::lookupDOMWrapper(V8ClassIndex::DOMWINDOW, m_global);
        ASSERT(!wrapper.IsEmpty());
        wrapper->TurnOnAccessCheck();

        // Separate the context from its global object.
        context()->DetachGlobal();

        disposeContextHandles();
    }
}
コード例 #19
0
PassRefPtr<JSONValue> ScriptValue::toJSONValue(ScriptState* scriptState) const
{
    v8::HandleScope handleScope(scriptState->isolate());
    // v8::Object::GetPropertyNames() expects current context to be not null.
    v8::Context::Scope contextScope(scriptState->context());
    return v8ToJSONValue(v8Value(), JSONValue::maxDepth, scriptState->isolate());
}
コード例 #20
0
ファイル: V8Proxy.cpp プロジェクト: jackiekaon/owb-mirror
void V8Proxy::updateDocumentWrapperCache()
{
    v8::HandleScope handleScope;
    v8::Context::Scope contextScope(context());

    // If the document has no frame, NodeToV8Object might get the
    // document wrapper for a document that is about to be deleted.
    // If the ForceSet below causes a garbage collection, the document
    // might get deleted and the global handle for the document
    // wrapper cleared. Using the cleared global handle will lead to
    // crashes. In this case we clear the cache and let the DOMWindow
    // accessor handle access to the document.
    if (!m_frame->document()->frame()) {
        clearDocumentWrapperCache();
        return;
    }

    v8::Handle<v8::Value> documentWrapper = V8DOMWrapper::convertNodeToV8Object(m_frame->document());

    // If instantiation of the document wrapper fails, clear the cache
    // and let the DOMWindow accessor handle access to the document.
    if (documentWrapper.IsEmpty()) {
        clearDocumentWrapperCache();
        return;
    }
    context()->Global()->ForceSet(v8::String::New("document"), documentWrapper, static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete));
}
コード例 #21
0
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;
}
コード例 #22
0
ファイル: AnimationTest.cpp プロジェクト: wangshijun/Blink
TEST_F(AnimationAnimationTest, TimingInputIterationStart)
{
    v8::Isolate* isolate = v8::Isolate::GetCurrent();
    v8::HandleScope scope(isolate);
    v8::Local<v8::Context> context = v8::Context::New(isolate);
    v8::Context::Scope contextScope(context);

    Timing timing;
    EXPECT_EQ(0, timing.iterationStart);

    applyTimingInputNumber(timing, isolate, "iterationStart", 1.1);
    EXPECT_EQ(1.1, timing.iterationStart);
    timing.iterationStart = 0;

    applyTimingInputNumber(timing, isolate, "iterationStart", -1);
    EXPECT_EQ(0, timing.iterationStart);
    timing.iterationStart = 0;

    applyTimingInputString(timing, isolate, "iterationStart", "Infinity");
    EXPECT_EQ(0, timing.iterationStart);
    timing.iterationStart = 0;

    applyTimingInputString(timing, isolate, "iterationStart", "-Infinity");
    EXPECT_EQ(0, timing.iterationStart);
    timing.iterationStart = 0;

    applyTimingInputString(timing, isolate, "iterationStart", "NaN");
    EXPECT_EQ(0, timing.iterationStart);
    timing.iterationStart = 0;

    applyTimingInputString(timing, isolate, "iterationStart", "rubbish");
    EXPECT_EQ(0, timing.iterationStart);
    timing.iterationStart = 0;
}
コード例 #23
0
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)));
}
コード例 #24
0
Page* InspectorOverlay::overlayPage()
{
    if (m_overlayPage)
        return m_overlayPage.get();

    static FrameLoaderClient* dummyFrameLoaderClient =  new EmptyFrameLoaderClient;
    Page::PageClients pageClients;
    fillWithEmptyClients(pageClients);
    ASSERT(!m_overlayChromeClient);
    m_overlayChromeClient = adoptPtr(new InspectorOverlayChromeClient(m_page->chrome().client(), this));
    pageClients.chromeClient = m_overlayChromeClient.get();
    m_overlayPage = adoptPtr(new Page(pageClients));
    m_overlayPage->setGroupType(Page::InspectorPageGroup);

    Settings* settings = m_page->settings();
    Settings* overlaySettings = m_overlayPage->settings();

    overlaySettings->setStandardFontFamily(settings->standardFontFamily());
    overlaySettings->setSerifFontFamily(settings->serifFontFamily());
    overlaySettings->setSansSerifFontFamily(settings->sansSerifFontFamily());
    overlaySettings->setCursiveFontFamily(settings->cursiveFontFamily());
    overlaySettings->setFantasyFontFamily(settings->fantasyFontFamily());
    overlaySettings->setPictographFontFamily(settings->pictographFontFamily());
    overlaySettings->setMinimumFontSize(settings->minimumFontSize());
    overlaySettings->setMinimumLogicalFontSize(settings->minimumLogicalFontSize());
    overlaySettings->setMediaEnabled(false);
    overlaySettings->setScriptEnabled(true);
    overlaySettings->setPluginsEnabled(false);
    overlaySettings->setLoadsImagesAutomatically(true);

    RefPtr<Frame> frame = Frame::create(m_overlayPage.get(), 0, dummyFrameLoaderClient);
    frame->setView(FrameView::create(frame.get()));
    frame->init();
    FrameLoader* loader = frame->loader();
    frame->view()->setCanHaveScrollbars(false);
    frame->view()->setTransparent(true);
    ASSERT(loader->activeDocumentLoader());
    loader->activeDocumentLoader()->writer()->setMIMEType("text/html");
    loader->activeDocumentLoader()->writer()->begin();
    loader->activeDocumentLoader()->writer()->addData(reinterpret_cast<const char*>(InspectorOverlayPage_html), sizeof(InspectorOverlayPage_html));
    loader->activeDocumentLoader()->writer()->end();

    v8::HandleScope handleScope;
    v8::Handle<v8::Context> frameContext = frame->script()->currentWorldContext();
    v8::Context::Scope contextScope(frameContext);
    v8::Handle<v8::Value> overlayHostObj = toV8(m_overlayHost.get(), v8::Handle<v8::Object>(), frameContext->GetIsolate());
    v8::Handle<v8::Object> global = frameContext->Global();
    global->Set(v8::String::New("InspectorOverlayHost"), overlayHostObj);

#if OS(WINDOWS)
    evaluateInOverlay("setPlatform", "windows");
#elif OS(DARWIN)
    evaluateInOverlay("setPlatform", "mac");
#elif OS(UNIX)
    evaluateInOverlay("setPlatform", "linux");
#endif

    return m_overlayPage.get();
}
コード例 #25
0
ScriptValue InjectedScriptHost::nodeAsScriptValue(ScriptState* state, Node* node)
{
    v8::HandleScope scope;
    v8::Local<v8::Context> context = state->context();
    v8::Context::Scope contextScope(context);

    return ScriptValue(toV8(node));
}
コード例 #26
0
void ScriptDebugServer::ensureDebuggerScriptCompiled()
{
    if (m_debuggerScript.get().IsEmpty()) {
        v8::HandleScope scope;
        v8::Local<v8::Context> debuggerContext = v8::Debug::GetDebugContext();
        v8::Context::Scope contextScope(debuggerContext);
        m_debuggerScript.set(v8::Handle<v8::Object>::Cast(v8::Script::Compile(v8String(m_debuggerScriptSource))->Run()));
    }
}
コード例 #27
0
int JavaScriptCallFrame::column() const
{
    v8::HandleScope handleScope;
    v8::Context::Scope contextScope(m_debuggerContext.get());
    v8::Handle<v8::Value> result = m_callFrame.get()->Get(v8String("column"));
    if (result->IsInt32())
        return result->Int32Value();
    return 0;
}
コード例 #28
0
void injectInternalsObject(v8::Local<v8::Context> context)
{
    v8::Context::Scope contextScope(context);
    v8::HandleScope scope;

    ScriptExecutionContext* scriptContext = getScriptExecutionContext();
    if (scriptContext->isDocument())
        context->Global()->Set(v8::String::New(Internals::internalsId), toV8(Internals::create(static_cast<Document*>(scriptContext))));
}
コード例 #29
0
void ScriptDebugServer::setPauseOnExceptionsState(PauseOnExceptionsState pauseOnExceptionsState)
{
    ensureDebuggerScriptCompiled();
    v8::HandleScope scope;
    v8::Context::Scope contextScope(v8::Debug::GetDebugContext());

    v8::Handle<v8::Value> argv[] = { v8::Int32::New(pauseOnExceptionsState) };
    callDebuggerMethod("setPauseOnExceptionsState", 1, argv);
}
コード例 #30
0
int JavaScriptCallFrame::column() const
{
    v8::HandleScope handleScope(m_isolate);
    v8::Context::Scope contextScope(m_debuggerContext.newLocal(m_isolate));
    v8::Handle<v8::Value> result = m_callFrame.newLocal(m_isolate)->Get(v8::String::NewSymbol("column"));
    if (result->IsInt32())
        return result->Int32Value();
    return 0;
}