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

Side by Side 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, 5 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/v8_inspector/V8DebuggerScript.h" 5 #include "platform/v8_inspector/V8DebuggerScript.h"
6 6
7 #include "platform/inspector_protocol/Collections.h"
8 #include "platform/v8_inspector/V8StringUtil.h"
9
7 namespace blink { 10 namespace blink {
8 11
9 V8DebuggerScript::V8DebuggerScript() 12 static const LChar hexDigits[17] = "0123456789ABCDEF";
10 : m_startLine(0) 13
11 , m_startColumn(0) 14 static void appendUnsignedAsHex(unsigned number, String16Builder* destination)
12 , m_endLine(0) 15 {
13 , m_endColumn(0) 16 for (size_t i = 0; i < 8; ++i) {
14 , m_executionContextId(0) 17 destination->append(hexDigits[number & 0xF]);
15 , m_isContentScript(false) 18 number >>= 4;
16 , m_isInternalScript(false) 19 }
17 , m_isLiveEdit(false) 20 }
21
22 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in
23 // eingeschränkten Branchingprogrammmodellen" by Woelfe.
24 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000
25 static String16 calculateHash(const String16& str)
26 {
27 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 };
28 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 };
29 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 };
30
31 uint64_t hashes[] = { 0, 0, 0, 0, 0 };
32 uint64_t zi[] = { 1, 1, 1, 1, 1 };
33
34 const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes);
35
36 size_t current = 0;
37 const uint32_t* data = nullptr;
38 data = reinterpret_cast<const uint32_t*>(str.characters16());
39 for (size_t i = 0; i < str.sizeInBytes() / 4; i += 4) {
40 uint32_t v = data[i];
41 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
42 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
43 zi[current] = (zi[current] * random[current]) % prime[current];
44 current = current == hashesSize - 1 ? 0 : current + 1;
45 }
46 if (str.sizeInBytes() % 4) {
47 uint32_t v = 0;
48 for (size_t i = str.sizeInBytes() - str.sizeInBytes() % 4; i < str.sizeI nBytes(); ++i) {
49 v <<= 8;
50 v |= reinterpret_cast<const uint8_t*>(data)[i];
51 }
52 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
53 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
54 zi[current] = (zi[current] * random[current]) % prime[current];
55 current = current == hashesSize - 1 ? 0 : current + 1;
56 }
57
58 for (size_t i = 0; i < hashesSize; ++i)
59 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i];
60
61 String16Builder hash;
62 for (size_t i = 0; i < hashesSize; ++i)
63 appendUnsignedAsHex(hashes[i], &hash);
64 return hash.toString();
65 }
66
67 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, v8::Local<v8::Object> o bject, bool isLiveEdit)
68 {
69 v8::Local<v8::Value> idValue = object->Get(toV8StringInternalized(isolate, " id"));
70 DCHECK(!idValue.IsEmpty() && idValue->IsInt32());
71 m_id = String16::number(idValue->Int32Value());
72
73 m_url = toProtocolStringWithTypeCheck(object->Get(toV8StringInternalized(iso late, "name")));
74 m_sourceURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInternaliz ed(isolate, "sourceURL")));
75 m_sourceMappingURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInt ernalized(isolate, "sourceMappingURL")));
76 m_startLine = object->Get(toV8StringInternalized(isolate, "startLine"))->ToI nteger(isolate)->Value();
77 m_startColumn = object->Get(toV8StringInternalized(isolate, "startColumn"))- >ToInteger(isolate)->Value();
78 m_endLine = object->Get(toV8StringInternalized(isolate, "endLine"))->ToInteg er(isolate)->Value();
79 m_endColumn = object->Get(toV8StringInternalized(isolate, "endColumn"))->ToI nteger(isolate)->Value();
80 m_isContentScript = object->Get(toV8StringInternalized(isolate, "isContentSc ript"))->ToBoolean(isolate)->Value();
81 m_isInternalScript = object->Get(toV8StringInternalized(isolate, "isInternal Script"))->ToBoolean(isolate)->Value();
82 m_executionContextId = object->Get(toV8StringInternalized(isolate, "executio nContextId"))->ToInteger(isolate)->Value();
83 m_isLiveEdit = isLiveEdit;
84
85 v8::Local<v8::Value> sourceValue = object->Get(toV8StringInternalized(isolat e, "source"));
86 if (!sourceValue.IsEmpty() && sourceValue->IsString())
87 setSource(isolate, sourceValue.As<v8::String>());
88 }
89
90 V8DebuggerScript::~V8DebuggerScript()
18 { 91 {
19 } 92 }
20 93
21 String16 V8DebuggerScript::sourceURL() const 94 String16 V8DebuggerScript::sourceURL() const
22 { 95 {
23 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; 96 return m_sourceURL.isEmpty() ? m_url : m_sourceURL;
24 } 97 }
25 98
26 V8DebuggerScript& V8DebuggerScript::setURL(const String16& url) 99 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const
27 { 100 {
28 m_url = url; 101 return m_source.Get(isolate);
29 return *this;
30 } 102 }
31 103
32 V8DebuggerScript& V8DebuggerScript::setSourceURL(const String16& sourceURL) 104 void V8DebuggerScript::setSourceURL(const String16& sourceURL)
33 { 105 {
34 m_sourceURL = sourceURL; 106 m_sourceURL = sourceURL;
35 return *this;
36 } 107 }
37 108
38 V8DebuggerScript& V8DebuggerScript::setSourceMappingURL(const String16& sourceMa ppingURL) 109 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL)
39 { 110 {
40 m_sourceMappingURL = sourceMappingURL; 111 m_sourceMappingURL = sourceMappingURL;
41 return *this;
42 } 112 }
43 113
44 V8DebuggerScript& V8DebuggerScript::setSource(const String16& source) 114 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce)
45 { 115 {
46 m_source = source; 116 m_source.Reset(isolate, source);
47 return *this; 117 m_hash = calculateHash(toProtocolString(source));
48 }
49
50 V8DebuggerScript& V8DebuggerScript::setHash(const String16& hash)
51 {
52 m_hash = hash;
53 return *this;
54 }
55
56 V8DebuggerScript& V8DebuggerScript::setStartLine(int startLine)
57 {
58 m_startLine = startLine;
59 return *this;
60 }
61
62 V8DebuggerScript& V8DebuggerScript::setStartColumn(int startColumn)
63 {
64 m_startColumn = startColumn;
65 return *this;
66 }
67
68 V8DebuggerScript& V8DebuggerScript::setEndLine(int endLine)
69 {
70 m_endLine = endLine;
71 return *this;
72 }
73
74 V8DebuggerScript& V8DebuggerScript::setEndColumn(int endColumn)
75 {
76 m_endColumn = endColumn;
77 return *this;
78 }
79
80 V8DebuggerScript& V8DebuggerScript::setExecutionContextId(int executionContextId )
81 {
82 m_executionContextId = executionContextId;
83 return *this;
84 }
85
86 V8DebuggerScript& V8DebuggerScript::setIsContentScript(bool isContentScript)
87 {
88 m_isContentScript = isContentScript;
89 return *this;
90 }
91
92 V8DebuggerScript& V8DebuggerScript::setIsInternalScript(bool isInternalScript)
93 {
94 m_isInternalScript = isInternalScript;
95 return *this;
96 }
97
98 V8DebuggerScript& V8DebuggerScript::setIsLiveEdit(bool isLiveEdit)
99 {
100 m_isLiveEdit = isLiveEdit;
101 return *this;
102 } 118 }
103 119
104 } // namespace blink 120 } // namespace blink
OLDNEW
« 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