Beispiel #1
0
void DaliWrapper::ApplyGlobalObjectsToContext( v8::Local<v8::Context> context )
{
  v8::HandleScope handleScope( mIsolate );

  // Add global objects ( functions/ values ) e.g. log function
  // create a console.log and console.error functions
  v8::Local<v8::ObjectTemplate> consoleObjectTemplate = v8::ObjectTemplate::New( mIsolate );
  consoleObjectTemplate->Set( v8::String::NewFromUtf8( mIsolate, "log"),   v8::FunctionTemplate::New( mIsolate, V8Utils::Log));
  consoleObjectTemplate->Set( v8::String::NewFromUtf8( mIsolate, "error"), v8::FunctionTemplate::New( mIsolate, V8Utils::LogError));

  context->Global()->Set( v8::String::NewFromUtf8( mIsolate, "console"), consoleObjectTemplate->NewInstance() );

  // add require functionality
  context->Global()->Set( v8::String::NewFromUtf8( mIsolate, "require"), v8::FunctionTemplate::New( mIsolate, DaliWrapper::Require)->GetFunction());

  // Create the Dali object
  // @todo consider forcing developers to perform require('dali') if we want to avoid polluting the global namespace
  v8::Local<v8::Object> daliObject = CreateDaliObject();

  // allow developers to require('dali'); // this is to maintain compatibility with node.js where dali is not part of the global namespace
  mModuleLoader.StorePreBuiltModule( mIsolate, daliObject, DALI_API_NAME );

  context->Global()->Set( v8::String::NewFromUtf8( mIsolate, DALI_API_NAME),daliObject );

}
Beispiel #2
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);
}
v8::MaybeLocal<v8::Value> MainThreadDebugger::memoryInfo(v8::Isolate* isolate, v8::Local<v8::Context> context)
{
    ExecutionContext* executionContext = toExecutionContext(context);
    ASSERT_UNUSED(executionContext, executionContext);
    ASSERT(executionContext->isDocument());
    return toV8(MemoryInfo::create(), context->Global(), isolate);
}
Beispiel #4
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))));
}
static v8::Local<v8::Object> toInnerGlobalObject(v8::Local<v8::Context> context)
{
    return v8::Local<v8::Object>::Cast(context->Global()->GetPrototype());
}