提交 094b491c 编写于 作者: Y Yury Semikhatsky

Remove ScriptPreprocessor

It is unused in Sky. I'm going to remove it in Blink too.

BUG=None
TBR=eseidel

Review URL: https://codereview.chromium.org/754463004
上级 1ace3930
......@@ -50,7 +50,6 @@ enum WorldIdConstants {
MainWorldId = 0,
// Embedder isolated worlds can use IDs in [1, 1<<29).
EmbedderWorldIdLimit = (1 << 29),
ScriptPreprocessorIsolatedWorldId,
IsolatedWorldIdLimit,
TestingWorldId,
};
......
......@@ -152,17 +152,6 @@ v8::Local<v8::Value> V8ScriptRunner::callInternalFunction(v8::Handle<v8::Functio
return result;
}
v8::Local<v8::Value> V8ScriptRunner::callAsFunction(v8::Isolate* isolate, v8::Handle<v8::Object> object, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> args[])
{
TRACE_EVENT0("v8", "v8.callFunction");
TRACE_EVENT_SCOPED_SAMPLING_STATE("v8", "V8Execution");
V8RecursionScope::MicrotaskSuppression recursionScope(isolate);
v8::Local<v8::Value> result = object->CallAsFunction(receiver, argc, args);
crashIfV8IsDead();
return result;
}
v8::Local<v8::Object> V8ScriptRunner::instantiateObject(v8::Isolate* isolate, v8::Handle<v8::ObjectTemplate> objectTemplate)
{
TRACE_EVENT0("v8", "v8.newInstance");
......
......@@ -57,7 +57,6 @@ public:
static v8::Local<v8::Value> runCompiledInternalScript(v8::Handle<v8::Script>, v8::Isolate*);
static v8::Local<v8::Value> callInternalFunction(v8::Handle<v8::Function>, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[], v8::Isolate*);
static v8::Local<v8::Value> callFunction(v8::Handle<v8::Function>, ExecutionContext*, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[], v8::Isolate*);
static v8::Local<v8::Value> callAsFunction(v8::Isolate*, v8::Handle<v8::Object>, v8::Handle<v8::Value> receiver, int argc, v8::Handle<v8::Value> info[]);
static v8::Local<v8::Object> instantiateObject(v8::Isolate*, v8::Handle<v8::ObjectTemplate>);
static v8::Local<v8::Object> instantiateObject(v8::Isolate*, v8::Handle<v8::Function>, int argc = 0, v8::Handle<v8::Value> argv[] = 0);
static v8::Local<v8::Object> instantiateObjectInDocument(v8::Isolate*, v8::Handle<v8::Function>, ExecutionContext*, int argc = 0, v8::Handle<v8::Value> argv[] = 0);
......
......@@ -66,8 +66,6 @@ component("v8_inspector") {
"ScriptDebugListener.h",
"ScriptDebugServer.cpp",
"ScriptDebugServer.h",
"ScriptPreprocessor.cpp",
"ScriptPreprocessor.h",
"ScriptRegexp.cpp",
"ScriptRegexp.h",
]
......
......@@ -155,7 +155,6 @@ void InspectorDebuggerAgent::disable()
scriptDebugServer().clearBreakpoints();
scriptDebugServer().clearCompiledScripts();
scriptDebugServer().clearPreprocessor();
stopListeningScriptDebugServer();
clear();
......@@ -274,16 +273,6 @@ void InspectorDebuggerAgent::addMessageToConsole(ConsoleMessage* consoleMessage)
breakProgram(InspectorFrontend::Debugger::Reason::Assert, nullptr);
}
String InspectorDebuggerAgent::preprocessEventListener(LocalFrame* frame, const String& source, const String& url, const String& functionName)
{
return scriptDebugServer().preprocessEventListener(frame, source, url, functionName);
}
PassOwnPtr<ScriptSourceCode> InspectorDebuggerAgent::preprocess(LocalFrame* frame, const ScriptSourceCode& sourceCode)
{
return scriptDebugServer().preprocess(frame, sourceCode);
}
static PassRefPtr<JSONObject> buildObjectForBreakpointCookie(const String& url, int lineNumber, int columnNumber, const String& condition, bool isRegex, bool isAnti)
{
RefPtr<JSONObject> breakpointObject = JSONObject::create();
......
......@@ -99,9 +99,6 @@ public:
bool runningNestedMessageLoop();
void addMessageToConsole(ConsoleMessage*);
String preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName);
PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&);
// Part of the protocol.
virtual void enable(ErrorString*) override final;
virtual void disable(ErrorString*) override final;
......
......@@ -100,7 +100,6 @@ void PageDebuggerAgent::setOverlayMessage(ErrorString*, const String* message)
void PageDebuggerAgent::didClearDocumentOfWindowObject(LocalFrame* frame)
{
reset();
scriptDebugServer().setPreprocessorSource(String());
}
} // namespace blink
......@@ -51,35 +51,6 @@
namespace blink {
static LocalFrame* retrieveFrameWithGlobalObjectCheck(v8::Handle<v8::Context> context)
{
if (context.IsEmpty())
return 0;
// FIXME: This is a temporary hack for crbug.com/345014.
// Currently it's possible that V8 can trigger Debugger::ProcessDebugEvent for a context
// that is being initialized (i.e., inside Context::New() of the context).
// We should fix the V8 side so that it won't trigger the event for a half-baked context
// because there is no way in the embedder side to check if the context is half-baked or not.
if (isMainThread() && DOMWrapperWorld::windowIsBeingInitialized())
return 0;
v8::Handle<v8::Value> global = V8Window::findInstanceInPrototypeChain(context->Global(), context->GetIsolate());
if (global.IsEmpty())
return 0;
return toFrameIfNotDetached(context);
}
void PageScriptDebugServer::setPreprocessorSource(const String& preprocessorSource)
{
if (preprocessorSource.isEmpty())
m_preprocessorSourceCode.clear();
else
m_preprocessorSourceCode = adoptPtr(new ScriptSourceCode(preprocessorSource));
m_scriptPreprocessor.clear();
}
PageScriptDebugServer& PageScriptDebugServer::shared()
{
DEFINE_STATIC_LOCAL(PageScriptDebugServer, server, ());
......@@ -221,83 +192,4 @@ void PageScriptDebugServer::quitMessageLoopOnPause()
m_clientMessageLoop->quitNow();
}
void PageScriptDebugServer::preprocessBeforeCompile(const v8::Debug::EventDetails& eventDetails)
{
v8::Handle<v8::Context> eventContext = eventDetails.GetEventContext();
LocalFrame* frame = retrieveFrameWithGlobalObjectCheck(eventContext);
if (!frame)
return;
if (!canPreprocess(frame))
return;
v8::Handle<v8::Object> eventData = eventDetails.GetEventData();
v8::Local<v8::Context> debugContext = v8::Debug::GetDebugContext();
v8::Context::Scope contextScope(debugContext);
v8::TryCatch tryCatch;
// <script> tag source and attribute value source are preprocessed before we enter V8.
// Avoid preprocessing any internal scripts by processing only eval source in this V8 event handler.
v8::Handle<v8::Value> argvEventData[] = { eventData };
v8::Handle<v8::Value> v8Value = callDebuggerMethod("isEvalCompilation", WTF_ARRAY_LENGTH(argvEventData), argvEventData);
if (v8Value.IsEmpty() || !v8Value->ToBoolean()->Value())
return;
// The name and source are in the JS event data.
String scriptName = toCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptName", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
String script = toCoreStringWithUndefinedOrNullCheck(callDebuggerMethod("getScriptSource", WTF_ARRAY_LENGTH(argvEventData), argvEventData));
String preprocessedSource = m_scriptPreprocessor->preprocessSourceCode(script, scriptName);
v8::Handle<v8::Value> argvPreprocessedScript[] = { eventData, v8String(debugContext->GetIsolate(), preprocessedSource) };
callDebuggerMethod("setScriptSource", WTF_ARRAY_LENGTH(argvPreprocessedScript), argvPreprocessedScript);
}
static bool isCreatingPreprocessor = false;
bool PageScriptDebugServer::canPreprocess(LocalFrame* frame)
{
ASSERT(frame);
if (!m_preprocessorSourceCode || isCreatingPreprocessor)
return false;
// We delay the creation of the preprocessor until just before the first JS from the
// Web page to ensure that the debugger's console initialization code has completed.
if (!m_scriptPreprocessor) {
TemporaryChange<bool> isPreprocessing(isCreatingPreprocessor, true);
m_scriptPreprocessor = adoptPtr(new ScriptPreprocessor(*m_preprocessorSourceCode.get(), frame));
}
if (m_scriptPreprocessor->isValid())
return true;
m_scriptPreprocessor.clear();
// Don't retry the compile if we fail one time.
m_preprocessorSourceCode.clear();
return false;
}
// Source to Source processing iff debugger enabled and it has loaded a preprocessor.
PassOwnPtr<ScriptSourceCode> PageScriptDebugServer::preprocess(LocalFrame* frame, const ScriptSourceCode& sourceCode)
{
if (!canPreprocess(frame))
return PassOwnPtr<ScriptSourceCode>();
String preprocessedSource = m_scriptPreprocessor->preprocessSourceCode(sourceCode.source(), sourceCode.url());
return adoptPtr(new ScriptSourceCode(preprocessedSource, sourceCode.url()));
}
String PageScriptDebugServer::preprocessEventListener(LocalFrame* frame, const String& source, const String& url, const String& functionName)
{
if (!canPreprocess(frame))
return source;
return m_scriptPreprocessor->preprocessSourceCode(source, url, functionName);
}
void PageScriptDebugServer::clearPreprocessor()
{
m_scriptPreprocessor.clear();
}
} // namespace blink
......@@ -32,7 +32,6 @@
#define SKY_ENGINE_V8_INSPECTOR_PAGESCRIPTDEBUGSERVER_H_
#include "sky/engine/v8_inspector/ScriptDebugServer.h"
#include "sky/engine/v8_inspector/ScriptPreprocessor.h"
#include "sky/engine/wtf/Forward.h"
#include "sky/engine/wtf/RefCounted.h"
#include "v8/include/v8.h"
......@@ -45,7 +44,6 @@ class InspectorHost;
namespace blink {
class ScriptController;
class ScriptPreprocessor;
class ScriptSourceCode;
class PageScriptDebugServer final : public ScriptDebugServer {
......@@ -78,11 +76,6 @@ public:
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace) override;
virtual void clearCompiledScripts() override;
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace) override;
virtual void setPreprocessorSource(const String&) override;
virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) override;
virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&) override;
virtual String preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName) override;
virtual void clearPreprocessor() override;
private:
PageScriptDebugServer();
......@@ -99,9 +92,6 @@ private:
inspector::InspectorHost* m_pausedHost;
HashMap<String, String> m_compiledScriptURLs;
OwnPtr<ScriptSourceCode> m_preprocessorSourceCode;
OwnPtr<ScriptPreprocessor> m_scriptPreprocessor;
bool canPreprocess(LocalFrame*);
static v8::Isolate* s_mainThreadIsolate;
};
......
......@@ -496,9 +496,7 @@ void ScriptDebugServer::handleV8DebugEvent(const v8::Debug::EventDetails& eventD
if (listener) {
v8::HandleScope scope(m_isolate);
v8::Handle<v8::Object> debuggerScript = m_debuggerScript.newLocal(m_isolate);
if (event == v8::BeforeCompile) {
preprocessBeforeCompile(eventDetails);
} else if (event == v8::AfterCompile || event == v8::CompileError) {
if (event == v8::AfterCompile || event == v8::CompileError) {
v8::Context::Scope contextScope(v8::Debug::GetDebugContext());
v8::Handle<v8::Function> getAfterCompileScript = v8::Local<v8::Function>::Cast(debuggerScript->Get(v8AtomicString(m_isolate, "getAfterCompileScript")));
v8::Handle<v8::Value> argv[] = { eventDetails.GetEventData() };
......@@ -703,14 +701,4 @@ void ScriptDebugServer::runScript(ScriptState* scriptState, const String& script
}
}
PassOwnPtr<ScriptSourceCode> ScriptDebugServer::preprocess(LocalFrame*, const ScriptSourceCode&)
{
return PassOwnPtr<ScriptSourceCode>();
}
String ScriptDebugServer::preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName)
{
return source;
}
} // namespace blink
\ No newline at end of file
......@@ -106,11 +106,6 @@ public:
virtual void compileScript(ScriptState*, const String& expression, const String& sourceURL, String* scriptId, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace);
virtual void clearCompiledScripts();
virtual void runScript(ScriptState*, const String& scriptId, ScriptValue* result, bool* wasThrown, String* exceptionDetailsText, int* lineNumber, int* columnNumber, RefPtr<ScriptCallStack>* stackTrace);
virtual void setPreprocessorSource(const String&) { }
virtual void preprocessBeforeCompile(const v8::Debug::EventDetails&) { }
virtual PassOwnPtr<ScriptSourceCode> preprocess(LocalFrame*, const ScriptSourceCode&);
virtual String preprocessEventListener(LocalFrame*, const String& source, const String& url, const String& functionName);
virtual void clearPreprocessor() { }
protected:
explicit ScriptDebugServer(v8::Isolate*);
......
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "sky/engine/config.h"
#include "sky/engine/v8_inspector/ScriptPreprocessor.h"
#include "sky/engine/bindings/core/v8/ScriptController.h"
#include "sky/engine/bindings/core/v8/ScriptSourceCode.h"
#include "sky/engine/bindings/core/v8/ScriptValue.h"
#include "sky/engine/bindings/core/v8/V8Binding.h"
#include "sky/engine/bindings/core/v8/V8ScriptRunner.h"
#include "sky/engine/core/frame/FrameConsole.h"
#include "sky/engine/core/frame/LocalFrame.h"
#include "sky/engine/core/inspector/ConsoleMessage.h"
#include "sky/engine/wtf/TemporaryChange.h"
namespace blink {
ScriptPreprocessor::ScriptPreprocessor(const ScriptSourceCode& preprocessorSourceCode, LocalFrame* frame)
: m_isPreprocessing(false)
{
RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(ScriptPreprocessorIsolatedWorldId, DOMWrapperWorld::mainWorldExtensionGroup);
m_scriptState = ScriptState::from(toV8Context(frame, *world));
v8::HandleScope handleScope(m_scriptState->isolate());
ASSERT(frame);
v8::TryCatch tryCatch;
tryCatch.SetVerbose(true);
Vector<ScriptSourceCode> sources;
sources.append(preprocessorSourceCode);
Vector<v8::Local<v8::Value> > scriptResults;
frame->script().executeScriptInIsolatedWorld(ScriptPreprocessorIsolatedWorldId, sources, DOMWrapperWorld::mainWorldExtensionGroup, &scriptResults);
if (scriptResults.size() != 1) {
frame->console().addMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, "ScriptPreprocessor internal error, one ScriptSourceCode must give exactly one result."));
return;
}
v8::Local<v8::Value> preprocessorFunction = scriptResults[0];
if (preprocessorFunction.IsEmpty() || !preprocessorFunction->IsFunction()) {
frame->console().addMessage(ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, "The preprocessor must compile to a function."));
return;
}
m_preprocessorFunction.set(m_scriptState->isolate(), v8::Handle<v8::Function>::Cast(preprocessorFunction));
}
String ScriptPreprocessor::preprocessSourceCode(const String& sourceCode, const String& sourceName)
{
if (!isValid())
return sourceCode;
return preprocessSourceCode(sourceCode, sourceName, v8::Undefined(m_scriptState->isolate()));
}
String ScriptPreprocessor::preprocessSourceCode(const String& sourceCode, const String& sourceName, const String& functionName)
{
if (!isValid())
return sourceCode;
v8::Handle<v8::String> functionNameString = v8String(m_scriptState->isolate(), functionName);
return preprocessSourceCode(sourceCode, sourceName, functionNameString);
}
String ScriptPreprocessor::preprocessSourceCode(const String& sourceCode, const String& sourceName, v8::Handle<v8::Value> functionName)
{
if (!isValid())
return sourceCode;
v8::Isolate* isolate = m_scriptState->isolate();
ScriptState::Scope scope(m_scriptState.get());
v8::Handle<v8::String> sourceCodeString = v8String(isolate, sourceCode);
v8::Handle<v8::String> sourceNameString = v8String(isolate, sourceName);
v8::Handle<v8::Value> argv[] = { sourceCodeString, sourceNameString, functionName};
v8::TryCatch tryCatch;
tryCatch.SetVerbose(true);
TemporaryChange<bool> isPreprocessing(m_isPreprocessing, true);
v8::Handle<v8::Value> resultValue = V8ScriptRunner::callAsFunction(isolate, m_preprocessorFunction.newLocal(isolate), m_scriptState->context()->Global(), WTF_ARRAY_LENGTH(argv), argv);
if (!resultValue.IsEmpty() && resultValue->IsString())
return toCoreStringWithNullCheck(resultValue.As<v8::String>());
return sourceCode;
}
} // namespace blink
/*
* Copyright (C) 2013 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SKY_ENGINE_V8_INSPECTOR_SCRIPTPREPROCESSOR_H_
#define SKY_ENGINE_V8_INSPECTOR_SCRIPTPREPROCESSOR_H_
#include "sky/engine/bindings/core/v8/V8Binding.h"
#include "sky/engine/wtf/RefCounted.h"
#include "sky/engine/wtf/text/WTFString.h"
#include "v8/include/v8.h"
namespace blink {
class ScriptController;
class ScriptSourceCode;
class ScriptDebugServer;
class ScriptPreprocessor {
WTF_MAKE_NONCOPYABLE(ScriptPreprocessor);
public:
ScriptPreprocessor(const ScriptSourceCode&, LocalFrame*);
String preprocessSourceCode(const String& sourceCode, const String& sourceName);
String preprocessSourceCode(const String& sourceCode, const String& sourceName, const String& functionName);
bool isPreprocessing() { return m_isPreprocessing; }
bool isValid() { return !m_preprocessorFunction.isEmpty(); }
private:
String preprocessSourceCode(const String& sourceCode, const String& sourceName, v8::Handle<v8::Value> functionName);
RefPtr<ScriptState> m_scriptState;
ScopedPersistent<v8::Function> m_preprocessorFunction;
bool m_isPreprocessing;
};
} // namespace blink
#endif // SKY_ENGINE_V8_INSPECTOR_SCRIPTPREPROCESSOR_H_
......@@ -256,8 +256,7 @@
"name": "reload",
"parameters": [
{ "name": "ignoreCache", "type": "boolean", "optional": true, "description": "If true, browser cache is ignored (as if the user pressed Shift+refresh)." },
{ "name": "scriptToEvaluateOnLoad", "type": "string", "optional": true, "description": "If set, the script will be injected into all frames of the inspected page after reload." },
{ "name": "scriptPreprocessor", "type": "string", "optional": true, "description": "Script body that should evaluate to function that will preprocess all the scripts before their compilation.", "hidden": true }
{ "name": "scriptToEvaluateOnLoad", "type": "string", "optional": true, "description": "If set, the script will be injected into all frames of the inspected page after reload." }
],
"description": "Reloads given page optionally ignoring the cache.",
"handlers": ["browser", "renderer"]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册