Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Unified Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp

Issue 2104063002: [DevTools] Store script source in v8::Global. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanup Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp
diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp
index 14dba693e97653e5c4ed0726e1f949a6977459ce..cc1b25191c6b8c6015bdfc7947d87da5ff67585b 100644
--- a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp
+++ b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp
@@ -4,101 +4,117 @@
#include "platform/v8_inspector/V8DebuggerScript.h"
-namespace blink {
-
-V8DebuggerScript::V8DebuggerScript()
- : m_startLine(0)
- , m_startColumn(0)
- , m_endLine(0)
- , m_endColumn(0)
- , m_executionContextId(0)
- , m_isContentScript(false)
- , m_isInternalScript(false)
- , m_isLiveEdit(false)
-{
-}
-
-String16 V8DebuggerScript::sourceURL() const
-{
- return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
-}
+#include "platform/inspector_protocol/Collections.h"
+#include "platform/v8_inspector/V8StringUtil.h"
-V8DebuggerScript& V8DebuggerScript::setURL(const String16& url)
-{
- m_url = url;
- return *this;
-}
-
-V8DebuggerScript& V8DebuggerScript::setSourceURL(const String16& sourceURL)
-{
- m_sourceURL = sourceURL;
- return *this;
-}
+namespace blink {
-V8DebuggerScript& V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL)
-{
- m_sourceMappingURL = sourceMappingURL;
- return *this;
-}
+static const LChar hexDigits[17] = "0123456789ABCDEF";
-V8DebuggerScript& V8DebuggerScript::setSource(const String16& source)
+static void appendUnsignedAsHex(unsigned number, String16Builder* destination)
{
- m_source = source;
- return *this;
+ for (size_t i = 0; i < 8; ++i) {
+ destination->append(hexDigits[number & 0xF]);
+ number >>= 4;
+ }
}
-V8DebuggerScript& V8DebuggerScript::setHash(const String16& hash)
+// Hash algorithm for substrings is described in "Über die Komplexität der Multiplikation in
+// eingeschränkten Branchingprogrammmodellen" by Woelfe.
+// http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECTION00832000000000000000
+static String16 calculateHash(const String16& str)
{
- m_hash = hash;
- return *this;
+ static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 };
+ static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 };
+ static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA11D, 0x8F462907 };
+
+ uint64_t hashes[] = { 0, 0, 0, 0, 0 };
+ uint64_t zi[] = { 1, 1, 1, 1, 1 };
+
+ const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes);
+
+ size_t current = 0;
+ const uint32_t* data = nullptr;
+ data = reinterpret_cast<const uint32_t*>(str.characters16());
+ for (size_t i = 0; i < str.sizeInBytes() / 4; i += 4) {
+ uint32_t v = data[i];
+ uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
+ hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
+ zi[current] = (zi[current] * random[current]) % prime[current];
+ current = current == hashesSize - 1 ? 0 : current + 1;
+ }
+ if (str.sizeInBytes() % 4) {
+ uint32_t v = 0;
+ for (size_t i = str.sizeInBytes() - str.sizeInBytes() % 4; i < str.sizeInBytes(); ++i) {
+ v <<= 8;
+ v |= reinterpret_cast<const uint8_t*>(data)[i];
+ }
+ uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
+ hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
+ zi[current] = (zi[current] * random[current]) % prime[current];
+ current = current == hashesSize - 1 ? 0 : current + 1;
+ }
+
+ for (size_t i = 0; i < hashesSize; ++i)
+ hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i];
+
+ String16Builder hash;
+ for (size_t i = 0; i < hashesSize; ++i)
+ appendUnsignedAsHex(hashes[i], &hash);
+ return hash.toString();
}
-V8DebuggerScript& V8DebuggerScript::setStartLine(int startLine)
+V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, v8::Local<v8::Object> object, bool isLiveEdit)
{
- m_startLine = startLine;
- return *this;
-}
+ v8::Local<v8::Value> idValue = object->Get(toV8StringInternalized(isolate, "id"));
+ DCHECK(!idValue.IsEmpty() && idValue->IsInt32());
+ m_id = String16::number(idValue->Int32Value());
+
+ m_url = toProtocolStringWithTypeCheck(object->Get(toV8StringInternalized(isolate, "name")));
+ m_sourceURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInternalized(isolate, "sourceURL")));
+ m_sourceMappingURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInternalized(isolate, "sourceMappingURL")));
+ m_startLine = object->Get(toV8StringInternalized(isolate, "startLine"))->ToInteger(isolate)->Value();
+ m_startColumn = object->Get(toV8StringInternalized(isolate, "startColumn"))->ToInteger(isolate)->Value();
+ m_endLine = object->Get(toV8StringInternalized(isolate, "endLine"))->ToInteger(isolate)->Value();
+ m_endColumn = object->Get(toV8StringInternalized(isolate, "endColumn"))->ToInteger(isolate)->Value();
+ m_isContentScript = object->Get(toV8StringInternalized(isolate, "isContentScript"))->ToBoolean(isolate)->Value();
+ m_isInternalScript = object->Get(toV8StringInternalized(isolate, "isInternalScript"))->ToBoolean(isolate)->Value();
+ m_executionContextId = object->Get(toV8StringInternalized(isolate, "executionContextId"))->ToInteger(isolate)->Value();
+ m_isLiveEdit = isLiveEdit;
-V8DebuggerScript& V8DebuggerScript::setStartColumn(int startColumn)
-{
- m_startColumn = startColumn;
- return *this;
+ v8::Local<v8::Value> sourceValue = object->Get(toV8StringInternalized(isolate, "source"));
+ if (!sourceValue.IsEmpty() && sourceValue->IsString())
+ setSource(isolate, sourceValue.As<v8::String>());
}
-V8DebuggerScript& V8DebuggerScript::setEndLine(int endLine)
+V8DebuggerScript::~V8DebuggerScript()
{
- m_endLine = endLine;
- return *this;
}
-V8DebuggerScript& V8DebuggerScript::setEndColumn(int endColumn)
+String16 V8DebuggerScript::sourceURL() const
{
- m_endColumn = endColumn;
- return *this;
+ return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
}
-V8DebuggerScript& V8DebuggerScript::setExecutionContextId(int executionContextId)
+v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const
{
- m_executionContextId = executionContextId;
- return *this;
+ return m_source.Get(isolate);
}
-V8DebuggerScript& V8DebuggerScript::setIsContentScript(bool isContentScript)
+void V8DebuggerScript::setSourceURL(const String16& sourceURL)
{
- m_isContentScript = isContentScript;
- return *this;
+ m_sourceURL = sourceURL;
}
-V8DebuggerScript& V8DebuggerScript::setIsInternalScript(bool isInternalScript)
+void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL)
{
- m_isInternalScript = isInternalScript;
- return *this;
+ m_sourceMappingURL = sourceMappingURL;
}
-V8DebuggerScript& V8DebuggerScript::setIsLiveEdit(bool isLiveEdit)
+void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> source)
{
- m_isLiveEdit = isLiveEdit;
- return *this;
+ m_source.Reset(isolate, source);
+ m_hash = calculateHash(toProtocolString(source));
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698