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

Side by Side Diff: third_party/WebKit/Source/platform/v8_inspector/V8DebuggerScript.cpp

Issue 2226863003: [DevTools] Reduce API surface of String16. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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" 7 #include "platform/inspector_protocol/Collections.h"
8 #include "platform/inspector_protocol/Platform.h" 8 #include "platform/inspector_protocol/Platform.h"
9 #include "platform/v8_inspector/V8StringUtil.h" 9 #include "platform/v8_inspector/V8StringUtil.h"
10 10
11 namespace blink { 11 namespace blink {
12 12
13 static const LChar hexDigits[17] = "0123456789ABCDEF"; 13 static const LChar hexDigits[17] = "0123456789ABCDEF";
14 14
15 static void appendUnsignedAsHex(unsigned number, String16Builder* destination) 15 static void appendUnsignedAsHex(unsigned number, String16Builder* destination)
16 { 16 {
17 for (size_t i = 0; i < 8; ++i) { 17 for (size_t i = 0; i < 8; ++i) {
18 destination->append(hexDigits[number & 0xF]); 18 UChar c = hexDigits[number & 0xF];
19 destination->append(c);
19 number >>= 4; 20 number >>= 4;
20 } 21 }
21 } 22 }
22 23
23 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in 24 // Hash algorithm for substrings is described in "Über die Komplexität der Multi plikation in
24 // eingeschränkten Branchingprogrammmodellen" by Woelfe. 25 // eingeschränkten Branchingprogrammmodellen" by Woelfe.
25 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000 26 // http://opendatastructures.org/versions/edition-0.1d/ods-java/node33.html#SECT ION00832000000000000000
26 static String16 calculateHash(const String16& str) 27 static String16 calculateHash(const String16& str)
27 { 28 {
28 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 }; 29 static uint64_t prime[] = { 0x3FB75161, 0xAB1F4E4F, 0x82675BC5, 0xCD924D35, 0x81ABE279 };
29 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }; 30 static uint64_t random[] = { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 };
30 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 }; 31 static uint32_t randomOdd[] = { 0xB4663807, 0xCC322BF5, 0xD4F91BBD, 0xA7BEA1 1D, 0x8F462907 };
31 32
32 uint64_t hashes[] = { 0, 0, 0, 0, 0 }; 33 uint64_t hashes[] = { 0, 0, 0, 0, 0 };
33 uint64_t zi[] = { 1, 1, 1, 1, 1 }; 34 uint64_t zi[] = { 1, 1, 1, 1, 1 };
34 35
35 const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes); 36 const size_t hashesSize = PROTOCOL_ARRAY_LENGTH(hashes);
36 37
37 size_t current = 0; 38 size_t current = 0;
38 const uint32_t* data = nullptr; 39 const uint32_t* data = nullptr;
40 size_t sizeInBytes = sizeof(UChar) * str.length();
39 data = reinterpret_cast<const uint32_t*>(str.characters16()); 41 data = reinterpret_cast<const uint32_t*>(str.characters16());
40 for (size_t i = 0; i < str.sizeInBytes() / 4; i += 4) { 42 for (size_t i = 0; i < sizeInBytes / 4; i += 4) {
41 uint32_t v = data[i]; 43 uint32_t v = data[i];
42 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; 44 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
43 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; 45 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
44 zi[current] = (zi[current] * random[current]) % prime[current]; 46 zi[current] = (zi[current] * random[current]) % prime[current];
45 current = current == hashesSize - 1 ? 0 : current + 1; 47 current = current == hashesSize - 1 ? 0 : current + 1;
46 } 48 }
47 if (str.sizeInBytes() % 4) { 49 if (sizeInBytes % 4) {
48 uint32_t v = 0; 50 uint32_t v = 0;
49 for (size_t i = str.sizeInBytes() - str.sizeInBytes() % 4; i < str.sizeI nBytes(); ++i) { 51 for (size_t i = sizeInBytes - sizeInBytes % 4; i < sizeInBytes; ++i) {
50 v <<= 8; 52 v <<= 8;
51 v |= reinterpret_cast<const uint8_t*>(data)[i]; 53 v |= reinterpret_cast<const uint8_t*>(data)[i];
52 } 54 }
53 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF; 55 uint64_t xi = v * randomOdd[current] & 0x7FFFFFFF;
54 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current]; 56 hashes[current] = (hashes[current] + zi[current] * xi) % prime[current];
55 zi[current] = (zi[current] * random[current]) % prime[current]; 57 zi[current] = (zi[current] * random[current]) % prime[current];
56 current = current == hashesSize - 1 ? 0 : current + 1; 58 current = current == hashesSize - 1 ? 0 : current + 1;
57 } 59 }
58 60
59 for (size_t i = 0; i < hashesSize; ++i) 61 for (size_t i = 0; i < hashesSize; ++i)
60 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i]; 62 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i];
61 63
62 String16Builder hash; 64 String16Builder hash;
63 for (size_t i = 0; i < hashesSize; ++i) 65 for (size_t i = 0; i < hashesSize; ++i)
64 appendUnsignedAsHex(hashes[i], &hash); 66 appendUnsignedAsHex(hashes[i], &hash);
65 return hash.toString(); 67 return hash.toString();
66 } 68 }
67 69
68 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, v8::Local<v8::Object> o bject, bool isLiveEdit) 70 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, v8::Local<v8::Object> o bject, bool isLiveEdit)
69 { 71 {
70 v8::Local<v8::Value> idValue = object->Get(toV8StringInternalized(isolate, " id")); 72 v8::Local<v8::Value> idValue = object->Get(toV8StringInternalized(isolate, " id"));
71 DCHECK(!idValue.IsEmpty() && idValue->IsInt32()); 73 DCHECK(!idValue.IsEmpty() && idValue->IsInt32());
72 m_id = String16::fromInteger(idValue->Int32Value()); 74 m_id = protocol::string16FromInteger(idValue->Int32Value());
73 75
74 m_url = toProtocolStringWithTypeCheck(object->Get(toV8StringInternalized(iso late, "name"))); 76 m_url = toProtocolStringWithTypeCheck(object->Get(toV8StringInternalized(iso late, "name")));
75 m_sourceURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInternaliz ed(isolate, "sourceURL"))); 77 m_sourceURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInternaliz ed(isolate, "sourceURL")));
76 m_sourceMappingURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInt ernalized(isolate, "sourceMappingURL"))); 78 m_sourceMappingURL = toProtocolStringWithTypeCheck(object->Get(toV8StringInt ernalized(isolate, "sourceMappingURL")));
77 m_startLine = object->Get(toV8StringInternalized(isolate, "startLine"))->ToI nteger(isolate)->Value(); 79 m_startLine = object->Get(toV8StringInternalized(isolate, "startLine"))->ToI nteger(isolate)->Value();
78 m_startColumn = object->Get(toV8StringInternalized(isolate, "startColumn"))- >ToInteger(isolate)->Value(); 80 m_startColumn = object->Get(toV8StringInternalized(isolate, "startColumn"))- >ToInteger(isolate)->Value();
79 m_endLine = object->Get(toV8StringInternalized(isolate, "endLine"))->ToInteg er(isolate)->Value(); 81 m_endLine = object->Get(toV8StringInternalized(isolate, "endLine"))->ToInteg er(isolate)->Value();
80 m_endColumn = object->Get(toV8StringInternalized(isolate, "endColumn"))->ToI nteger(isolate)->Value(); 82 m_endColumn = object->Get(toV8StringInternalized(isolate, "endColumn"))->ToI nteger(isolate)->Value();
81 m_executionContextAuxData = toProtocolStringWithTypeCheck(object->Get(toV8St ringInternalized(isolate, "executionContextAuxData"))); 83 m_executionContextAuxData = toProtocolStringWithTypeCheck(object->Get(toV8St ringInternalized(isolate, "executionContextAuxData")));
82 m_isInternalScript = object->Get(toV8StringInternalized(isolate, "isInternal Script"))->ToBoolean(isolate)->Value(); 84 m_isInternalScript = object->Get(toV8StringInternalized(isolate, "isInternal Script"))->ToBoolean(isolate)->Value();
(...skipping 29 matching lines...) Expand all
112 m_sourceMappingURL = sourceMappingURL; 114 m_sourceMappingURL = sourceMappingURL;
113 } 115 }
114 116
115 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce) 117 void V8DebuggerScript::setSource(v8::Isolate* isolate, v8::Local<v8::String> sou rce)
116 { 118 {
117 m_source.Reset(isolate, source); 119 m_source.Reset(isolate, source);
118 m_hash = calculateHash(toProtocolString(source)); 120 m_hash = calculateHash(toProtocolString(source));
119 } 121 }
120 122
121 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698