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);
}
예제 #2
0
static bool codeGenerationCheckCallbackInMainThread(v8::Local<v8::Context> context)
{
    if (ExecutionContext* executionContext = toExecutionContext(context)) {
        if (ContentSecurityPolicy* policy = toDocument(executionContext)->contentSecurityPolicy())
            return policy->allowEval(ScriptState::from(context), ContentSecurityPolicy::SendReport, ContentSecurityPolicy::WillThrowException);
    }
    return false;
}
예제 #3
0
ExecutionContext* activeExecutionContext()
{
    v8::Handle<v8::Context> context = v8::Isolate::GetCurrent()->GetCallingContext();
    if (context.IsEmpty()) {
        // Unfortunately, when processing script from a plug-in, we might not
        // have a calling context. In those cases, we fall back to the
        // entered context.
        context = v8::Isolate::GetCurrent()->GetEnteredContext();
    }
    return toExecutionContext(context);
}
static Node* secondArgumentAsNode(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (info.Length() > 1) {
        if (Node* node = V8Node::toImplWithTypeCheck(info.GetIsolate(), info[1]))
            return node;
    }
    ExecutionContext* executionContext = toExecutionContext(info.GetIsolate()->GetCurrentContext());
    if (executionContext->isDocument())
        return toDocument(executionContext);
    return nullptr;
}
예제 #5
0
AtomicString V8CustomXPathNSResolver::lookupNamespaceURI(const String& prefix) {
  v8::Isolate* isolate = m_scriptState->isolate();
  v8::Local<v8::Function> lookupNamespaceURIFunc;
  v8::Local<v8::String> lookupNamespaceURIName =
      v8AtomicString(isolate, "lookupNamespaceURI");

  // Check if the resolver has a function property named lookupNamespaceURI.
  v8::Local<v8::Value> lookupNamespaceURI;
  if (m_resolver->Get(m_scriptState->context(), lookupNamespaceURIName)
          .ToLocal(&lookupNamespaceURI) &&
      lookupNamespaceURI->IsFunction())
    lookupNamespaceURIFunc = v8::Local<v8::Function>::Cast(lookupNamespaceURI);

  if (lookupNamespaceURIFunc.IsEmpty() && !m_resolver->IsFunction()) {
    LocalFrame* frame =
        toLocalDOMWindow(toDOMWindow(m_scriptState->context()))->frame();
    if (frame && frame->host())
      frame->console().addMessage(ConsoleMessage::create(
          JSMessageSource, ErrorMessageLevel,
          "XPathNSResolver does not have a lookupNamespaceURI method."));
    return nullAtom;
  }

  // Catch exceptions from calling the namespace resolver.
  v8::TryCatch tryCatch(isolate);
  tryCatch.SetVerbose(true);  // Print exceptions to console.

  const int argc = 1;
  v8::Local<v8::Value> argv[argc] = {v8String(isolate, prefix)};
  v8::Local<v8::Function> function =
      lookupNamespaceURIFunc.IsEmpty()
          ? v8::Local<v8::Function>::Cast(m_resolver)
          : lookupNamespaceURIFunc;

  v8::Local<v8::Value> retval;
  // Eat exceptions from namespace resolver and return an empty string. This
  // will most likely cause NamespaceError.
  if (!V8ScriptRunner::callFunction(
           function, toExecutionContext(m_scriptState->context()), m_resolver,
           argc, argv, isolate)
           .ToLocal(&retval))
    return nullAtom;

  TOSTRING_DEFAULT(V8StringResource<TreatNullAsNullString>, returnString,
                   retval, nullAtom);
  return returnString;
}
예제 #6
0
ExecutionContext* ScriptState::executionContext() const
{
    v8::HandleScope scope(m_isolate);
    return toExecutionContext(context());
}