Esempio n. 1
0
V8PerContextData::V8PerContextData(v8::Local<v8::Context> context)
    : m_isolate(context->GetIsolate()),
      m_wrapperBoilerplates(m_isolate),
      m_constructorMap(m_isolate),
      m_contextHolder(WTF::makeUnique<gin::ContextHolder>(m_isolate)),
      m_context(m_isolate, context),
      m_activityLogger(0),
      m_compiledPrivateScript(m_isolate) {
  m_contextHolder->SetContext(context);

  v8::Context::Scope contextScope(context);
  ASSERT(m_errorPrototype.isEmpty());
  v8::Local<v8::Value> objectValue =
      context->Global()
          ->Get(context, v8AtomicString(m_isolate, "Error"))
          .ToLocalChecked();
  v8::Local<v8::Value> prototypeValue =
      objectValue.As<v8::Object>()
          ->Get(context, v8AtomicString(m_isolate, "prototype"))
          .ToLocalChecked();
  m_errorPrototype.set(m_isolate, prototypeValue);

  if (isMainThread())
    InstanceCounters::incrementCounter(
        InstanceCounters::V8PerContextDataCounter);
}
Esempio n. 2
0
bool markAsInternal(v8::Local<v8::Context> context, v8::Local<v8::Object> object, V8InternalValueType type)
{
    v8::Isolate* isolate = context->GetIsolate();
    v8::Local<v8::Private> privateValue = internalSubtypePrivate(isolate);
    v8::Local<v8::String> subtype = subtypeForInternalType(isolate, type);
    return object->SetPrivate(context, privateValue, subtype).FromMaybe(false);
}
Esempio n. 3
0
v8::Local<v8::Value> v8InternalValueTypeFrom(v8::Local<v8::Context> context, v8::Local<v8::Object> object)
{
    v8::Isolate* isolate = context->GetIsolate();
    v8::Local<v8::Private> privateValue = internalSubtypePrivate(isolate);
    if (!object->HasPrivate(context, privateValue).FromMaybe(false))
        return v8::Null(isolate);
    v8::Local<v8::Value> subtypeValue;
    if (!object->GetPrivate(context, privateValue).ToLocal(&subtypeValue) || !subtypeValue->IsString())
        return v8::Null(isolate);
    return subtypeValue;
}
void V8TestInterfacePartial::preparePrototypeAndInterfaceObject(v8::Local<v8::Context> context, v8::Local<v8::Object> prototypeObject, v8::Local<v8::Function> interfaceObject, v8::Local<v8::FunctionTemplate> interfaceTemplate)
{
    V8TestInterface::preparePrototypeAndInterfaceObject(context, prototypeObject, interfaceObject, interfaceTemplate);
    v8::Isolate* isolate = context->GetIsolate();
    v8::Local<v8::Name> unscopablesSymbol(v8::Symbol::GetUnscopables(isolate));
    v8::Local<v8::Object> unscopeables;
    if (v8CallBoolean(prototypeObject->HasOwnProperty(context, unscopablesSymbol)))
        unscopeables = prototypeObject->Get(context, unscopablesSymbol).ToLocalChecked().As<v8::Object>();
    else
        unscopeables = v8::Object::New(isolate);
    unscopeables->CreateDataProperty(context, v8AtomicString(isolate, "unscopeableVoidMethod"), v8::True(isolate)).FromJust();
    prototypeObject->CreateDataProperty(context, unscopablesSymbol, unscopeables).FromJust();
}
Esempio n. 5
0
ScriptState::ScriptState(v8::Local<v8::Context> context, PassRefPtr<DOMWrapperWorld> world)
    : m_isolate(context->GetIsolate())
    , m_context(m_isolate, context)
    , m_world(world)
    , m_perContextData(V8PerContextData::create(context))
#if ENABLE(ASSERT)
    , m_globalObjectDetached(false)
#endif
{
    ASSERT(m_world);
    m_context.setWeak(this, &weakCallback);
    context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, this);
}
Esempio n. 6
0
bool markArrayEntriesAsInternal(v8::Local<v8::Context> context, v8::Local<v8::Array> array, V8InternalValueType type)
{
    v8::Isolate* isolate = context->GetIsolate();
    v8::Local<v8::Private> privateValue = internalSubtypePrivate(isolate);
    v8::Local<v8::String> subtype = subtypeForInternalType(isolate, type);
    for (size_t i = 0; i < array->Length(); ++i) {
        v8::Local<v8::Value> entry;
        if (!array->Get(context, i).ToLocal(&entry) || !entry->IsObject())
            return false;
        if (!entry.As<v8::Object>()->SetPrivate(context, privateValue, subtype).FromMaybe(false))
            return false;
    }
    return true;
}
Esempio n. 7
0
// The read-eval-execute loop of the shell.
void Fragment::Script::ScriptEngine::RunShell(v8::Local<v8::Context> context, v8::Platform *platform) {
    fprintf(stderr, "V8 version %s [sample shell]\n", v8::V8::GetVersion());
    static const int kBufferSize = 256;
    // Enter the execution environment before evaluating any code.
    v8::Context::Scope context_scope(context);
    v8::Local<v8::String> name(
            v8::String::NewFromUtf8(context->GetIsolate(), "(shell)",
                                    v8::NewStringType::kNormal).ToLocalChecked());
    while (true) {
        char buffer[kBufferSize];
        fprintf(stderr, "> ");
        char *str = fgets(buffer, kBufferSize, stdin);
        if (str == NULL) break;
        v8::HandleScope handle_scope(context->GetIsolate());
        ExecuteString(
                context->GetIsolate(),
                v8::String::NewFromUtf8(context->GetIsolate(), str,
                                        v8::NewStringType::kNormal).ToLocalChecked(),
                name, true, true);
        while (v8::platform::PumpMessageLoop(platform, context->GetIsolate()))
            continue;
    }
    fprintf(stderr, "\n");
}
void MainThreadDebugger::runMessageLoopOnPause(v8::Local<v8::Context> context)
{
    v8::HandleScope scope(context->GetIsolate());
    LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(context);
    m_pausedFrame = frame->localFrameRoot();

    // Wait for continue or step command.
    m_clientMessageLoop->run(m_pausedFrame);

    // The listener may have been removed in the nested loop.
    if (ScriptDebugListener* listener = m_listenersMap.get(m_pausedFrame))
        listener->didContinue();

    m_pausedFrame = 0;
}
v8::Local<v8::Object> InspectorWrapperBase::createWrapper(v8::Local<v8::FunctionTemplate> constructorTemplate, v8::Local<v8::Context> context)
{
    v8::Local<v8::Function> function;
    if (!constructorTemplate->GetFunction(context).ToLocal(&function))
        return v8::Local<v8::Object>();

    // FIXME: don't depend on V8ScriptRunner
    v8::Isolate* isolate = context->GetIsolate();
    v8::MaybeLocal<v8::Object> maybeResult = V8ScriptRunner::instantiateObject(isolate, function);
    v8::Local<v8::Object> result;
    if (!maybeResult.ToLocal(&result))
        return v8::Local<v8::Object>();

    return result;
}
Esempio n. 10
0
  static void Init(v8::Local<v8::Object> exports) {
      Isolate* isolate = exports->GetIsolate();

      // Prepare constructor template
      Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
      tpl->SetClassName(String::NewFromUtf8(isolate, "Polynomial"));
      tpl->InstanceTemplate()->SetInternalFieldCount(1);

      // Prototype
      NODE_SET_PROTOTYPE_METHOD(tpl, "at", At);
      NODE_SET_PROTOTYPE_METHOD(tpl, "roots", Roots);
     
      tpl->InstanceTemplate()->SetAccessor(String::NewFromUtf8(isolate, "a"), GetCoeff, SetCoeff);
      tpl->InstanceTemplate()->SetAccessor(String::NewFromUtf8(isolate, "b"), GetCoeff, SetCoeff);
      tpl->InstanceTemplate()->SetAccessor(String::NewFromUtf8(isolate, "c"), GetCoeff, SetCoeff);

      constructor.Reset(isolate, tpl->GetFunction());
      exports->Set(String::NewFromUtf8(isolate, "Polynomial"),
               tpl->GetFunction());
  }
Esempio n. 11
0
CJS_Object::CJS_Object(v8::Local<v8::Object> pObject) {
  m_pIsolate = pObject->GetIsolate();
  m_pV8Object.Reset(m_pIsolate, pObject);
}
Esempio n. 12
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)), v8::Handle<v8::Object>(), context->GetIsolate()));
}