void V8DOMWindowShell::updateDocument() { ASSERT(m_world->isMainWorld()); if (m_global.isEmpty()) return; if (!initializeIfNeeded()) return; updateDocumentProperty(); updateSecurityOrigin(); }
void WindowProxy::setGlobal(v8::Local<v8::Object> global) { m_global.set(m_isolate, global); // Initialize the window proxy now, to re-establish the connection between // the global object and the v8::Context. This is really only needed for a // RemoteDOMWindow, since it has no scripting environment of its own. // Without this, existing script references to a swapped in RemoteDOMWindow // would be broken until that RemoteDOMWindow was vended again through an // interface like window.frames. initializeIfNeeded(); }
void V8DOMWindowShell::namedItemAdded(HTMLDocument* document, const AtomicString& name) { ASSERT(m_world->isMainWorld()); if (!initializeIfNeeded()) return; v8::HandleScope handleScope; v8::Context::Scope contextScope(m_context.get()); ASSERT(!m_document.isEmpty()); checkDocumentWrapper(m_document.get(), document); m_document->SetAccessor(v8String(name), getter); }
ScriptValue WorkerContextExecutionProxy::evaluate(const String& script, const String& fileName, const TextPosition& scriptStartPosition, WorkerContextExecutionState* state) { V8GCController::checkMemoryUsage(); v8::HandleScope hs; if (!initializeIfNeeded()) return ScriptValue(); if (!m_disableEvalPending.isEmpty()) { m_context->AllowCodeGenerationFromStrings(false); m_context->SetErrorMessageForCodeGenerationFromStrings(v8String(m_disableEvalPending)); m_disableEvalPending = String(); } v8::Context::Scope scope(m_context); v8::TryCatch exceptionCatcher; v8::Local<v8::String> scriptString = v8ExternalString(script); v8::Handle<v8::Script> compiledScript = ScriptSourceCode::compileScript(scriptString, fileName, scriptStartPosition); v8::Local<v8::Value> result = ScriptRunner::runCompiledScript(compiledScript, m_workerContext); if (!exceptionCatcher.CanContinue()) { m_workerContext->script()->forbidExecution(); return ScriptValue(); } if (exceptionCatcher.HasCaught()) { v8::Local<v8::Message> message = exceptionCatcher.Message(); state->hadException = true; state->errorMessage = toWebCoreString(message->Get()); state->lineNumber = message->GetLineNumber(); state->sourceURL = toWebCoreString(message->GetScriptResourceName()); if (m_workerContext->sanitizeScriptError(state->errorMessage, state->lineNumber, state->sourceURL)) state->exception = throwError(GeneralError, state->errorMessage.utf8().data()); else state->exception = ScriptValue(exceptionCatcher.Exception()); exceptionCatcher.Reset(); } else state->hadException = false; if (result.IsEmpty() || result->IsUndefined()) return ScriptValue(); return ScriptValue(result); }
void V8DOMWindowShell::namedItemRemoved(HTMLDocument* document, const AtomicString& name) { ASSERT(m_world->isMainWorld()); if (document->hasNamedItem(name.impl()) || document->hasExtraNamedItem(name.impl())) return; if (!initializeIfNeeded()) return; v8::HandleScope handleScope; v8::Context::Scope contextScope(m_context.get()); ASSERT(!m_document.isEmpty()); checkDocumentWrapper(m_document.get(), document); m_document->Delete(v8String(name)); }
void WindowProxy::takeGlobalFrom(WindowProxy* windowProxy) { v8::HandleScope handleScope(m_isolate); ASSERT(!windowProxy->isContextInitialized()); // If a ScriptState was created, the context was initialized at some point. // Make sure the global object was detached from the proxy by calling clearForNavigation(). if (windowProxy->m_scriptState) ASSERT(windowProxy->m_scriptState->isGlobalObjectDetached()); m_global.set(m_isolate, windowProxy->m_global.newLocal(m_isolate)); windowProxy->m_global.clear(); // Initialize the window proxy now, to re-establish the connection between // the global object and the v8::Context. This is really only needed for a // RemoteDOMWindow, since it has no scripting environment of its own. // Without this, existing script references to a swapped in RemoteDOMWindow // would be broken until that RemoteDOMWindow was vended again through an // interface like window.frames. initializeIfNeeded(); }
bool MockSpellCheck::spellCheckWord(const WebString& text, int* misspelledOffset, int* misspelledLength) { WEBKIT_ASSERT(misspelledOffset); WEBKIT_ASSERT(misspelledLength); // Initialize this spellchecker. initializeIfNeeded(); // Reset the result values as our spellchecker does. *misspelledOffset = 0; *misspelledLength = 0; // Convert to a string16 because we store string16 instances in // m_misspelledWords and WebString has no find(). string16 stringText = text; int skippedLength = 0; while (!stringText.empty()) { // Extract the first possible English word from the given string. // The given string may include non-ASCII characters or numbers. So, we // should filter out such characters before start looking up our // misspelled-word table. // (This is a simple version of our SpellCheckWordIterator class.) // If the given string doesn't include any ASCII characters, we can treat the // string as valid one. string16::iterator firstChar = find_if(stringText.begin(), stringText.end(), isASCIIAlpha); if (firstChar == stringText.end()) return true; int wordOffset = distance(stringText.begin(), firstChar); int maxWordLength = static_cast<int>(stringText.length()) - wordOffset; int wordLength; string16 word; // Look up our misspelled-word table to check if the extracted word is a // known misspelled word, and return the offset and the length of the // extracted word if this word is a known misspelled word. // (See the comment in MockSpellCheck::initializeIfNeeded() why we use a // misspelled-word table.) for (size_t i = 0; i < m_misspelledWords.size(); ++i) { wordLength = static_cast<int>(m_misspelledWords.at(i).length()) > maxWordLength ? maxWordLength : static_cast<int>(m_misspelledWords.at(i).length()); word = stringText.substr(wordOffset, wordLength); if (word == m_misspelledWords.at(i) && (static_cast<int>(stringText.length()) == wordOffset + wordLength || isNotASCIIAlpha(stringText[wordOffset + wordLength]))) { *misspelledOffset = wordOffset + skippedLength; *misspelledLength = wordLength; break; } } if (*misspelledLength > 0) break; string16::iterator lastChar = find_if(stringText.begin() + wordOffset, stringText.end(), isNotASCIIAlpha); if (lastChar == stringText.end()) wordLength = static_cast<int>(stringText.length()) - wordOffset; else wordLength = distance(firstChar, lastChar); WEBKIT_ASSERT(0 < wordOffset + wordLength); stringText = stringText.substr(wordOffset + wordLength); skippedLength += wordOffset + wordLength; } return false; }