| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project 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 "src/inspector/V8DebuggerScript.h" | 5 #include "src/inspector/V8DebuggerScript.h" |
| 6 | 6 |
| 7 #include "src/inspector/ProtocolPlatform.h" | 7 #include "src/inspector/ProtocolPlatform.h" |
| 8 #include "src/inspector/StringUtil.h" | 8 #include "src/inspector/StringUtil.h" |
| 9 | 9 |
| 10 namespace v8_inspector { | 10 namespace v8_inspector { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 | 61 |
| 62 for (size_t i = 0; i < hashesSize; ++i) | 62 for (size_t i = 0; i < hashesSize; ++i) |
| 63 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i]; | 63 hashes[i] = (hashes[i] + zi[i] * (prime[i] - 1)) % prime[i]; |
| 64 | 64 |
| 65 String16Builder hash; | 65 String16Builder hash; |
| 66 for (size_t i = 0; i < hashesSize; ++i) appendUnsignedAsHex(hashes[i], &hash); | 66 for (size_t i = 0; i < hashesSize; ++i) appendUnsignedAsHex(hashes[i], &hash); |
| 67 return hash.toString(); | 67 return hash.toString(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 V8DebuggerScript::V8DebuggerScript(v8::Isolate* isolate, | 70 static v8::Local<v8::Value> GetChecked(v8::Local<v8::Context> context, |
| 71 v8::Local<v8::Object> object, |
| 72 const char* name) { |
| 73 return object |
| 74 ->Get(context, toV8StringInternalized(context->GetIsolate(), name)) |
| 75 .ToLocalChecked(); |
| 76 } |
| 77 |
| 78 static int64_t GetCheckedInt(v8::Local<v8::Context> context, |
| 79 v8::Local<v8::Object> object, const char* name) { |
| 80 return GetChecked(context, object, name) |
| 81 ->ToInteger(context) |
| 82 .ToLocalChecked() |
| 83 ->Value(); |
| 84 } |
| 85 |
| 86 V8DebuggerScript::V8DebuggerScript(v8::Local<v8::Context> context, |
| 71 v8::Local<v8::Object> object, | 87 v8::Local<v8::Object> object, |
| 72 bool isLiveEdit) { | 88 bool isLiveEdit) { |
| 73 v8::Local<v8::Value> idValue = | 89 v8::Isolate* isolate = context->GetIsolate(); |
| 74 object->Get(toV8StringInternalized(isolate, "id")); | 90 v8::Local<v8::Value> idValue = GetChecked(context, object, "id"); |
| 75 DCHECK(!idValue.IsEmpty() && idValue->IsInt32()); | 91 DCHECK(!idValue.IsEmpty() && idValue->IsInt32()); |
| 76 m_id = String16::fromInteger(idValue->Int32Value()); | 92 m_id = String16::fromInteger(idValue->Int32Value(context).FromJust()); |
| 77 | 93 |
| 78 m_url = toProtocolStringWithTypeCheck( | 94 m_url = toProtocolStringWithTypeCheck(GetChecked(context, object, "name")); |
| 79 object->Get(toV8StringInternalized(isolate, "name"))); | 95 m_sourceURL = |
| 80 m_sourceURL = toProtocolStringWithTypeCheck( | 96 toProtocolStringWithTypeCheck(GetChecked(context, object, "sourceURL")); |
| 81 object->Get(toV8StringInternalized(isolate, "sourceURL"))); | |
| 82 m_sourceMappingURL = toProtocolStringWithTypeCheck( | 97 m_sourceMappingURL = toProtocolStringWithTypeCheck( |
| 83 object->Get(toV8StringInternalized(isolate, "sourceMappingURL"))); | 98 GetChecked(context, object, "sourceMappingURL")); |
| 84 m_startLine = object->Get(toV8StringInternalized(isolate, "startLine")) | 99 m_startLine = GetCheckedInt(context, object, "startLine"); |
| 85 ->ToInteger(isolate) | 100 m_startColumn = GetCheckedInt(context, object, "startColumn"); |
| 86 ->Value(); | 101 m_endLine = GetCheckedInt(context, object, "endLine"); |
| 87 m_startColumn = object->Get(toV8StringInternalized(isolate, "startColumn")) | 102 m_endColumn = GetCheckedInt(context, object, "endColumn"); |
| 88 ->ToInteger(isolate) | |
| 89 ->Value(); | |
| 90 m_endLine = object->Get(toV8StringInternalized(isolate, "endLine")) | |
| 91 ->ToInteger(isolate) | |
| 92 ->Value(); | |
| 93 m_endColumn = object->Get(toV8StringInternalized(isolate, "endColumn")) | |
| 94 ->ToInteger(isolate) | |
| 95 ->Value(); | |
| 96 m_executionContextAuxData = toProtocolStringWithTypeCheck( | 103 m_executionContextAuxData = toProtocolStringWithTypeCheck( |
| 97 object->Get(toV8StringInternalized(isolate, "executionContextAuxData"))); | 104 GetChecked(context, object, "executionContextAuxData")); |
| 98 m_executionContextId = | 105 m_executionContextId = GetCheckedInt(context, object, "executionContextId"); |
| 99 object->Get(toV8StringInternalized(isolate, "executionContextId")) | |
| 100 ->ToInteger(isolate) | |
| 101 ->Value(); | |
| 102 m_isLiveEdit = isLiveEdit; | 106 m_isLiveEdit = isLiveEdit; |
| 103 | 107 |
| 104 v8::Local<v8::Value> sourceValue = | 108 v8::Local<v8::Value> sourceValue; |
| 105 object->Get(toV8StringInternalized(isolate, "source")); | 109 if (!object->Get(context, toV8StringInternalized(isolate, "source")) |
| 106 if (!sourceValue.IsEmpty() && sourceValue->IsString()) | 110 .ToLocal(&sourceValue) || |
| 107 setSource(isolate, sourceValue.As<v8::String>()); | 111 !sourceValue->IsString()) |
| 112 return; |
| 113 setSource(isolate, sourceValue.As<v8::String>()); |
| 108 } | 114 } |
| 109 | 115 |
| 110 V8DebuggerScript::~V8DebuggerScript() {} | 116 V8DebuggerScript::~V8DebuggerScript() {} |
| 111 | 117 |
| 112 const String16& V8DebuggerScript::sourceURL() const { | 118 const String16& V8DebuggerScript::sourceURL() const { |
| 113 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; | 119 return m_sourceURL.isEmpty() ? m_url : m_sourceURL; |
| 114 } | 120 } |
| 115 | 121 |
| 116 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { | 122 v8::Local<v8::String> V8DebuggerScript::source(v8::Isolate* isolate) const { |
| 117 return m_source.Get(isolate); | 123 return m_source.Get(isolate); |
| 118 } | 124 } |
| 119 | 125 |
| 120 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { | 126 void V8DebuggerScript::setSourceURL(const String16& sourceURL) { |
| 121 m_sourceURL = sourceURL; | 127 m_sourceURL = sourceURL; |
| 122 } | 128 } |
| 123 | 129 |
| 124 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { | 130 void V8DebuggerScript::setSourceMappingURL(const String16& sourceMappingURL) { |
| 125 m_sourceMappingURL = sourceMappingURL; | 131 m_sourceMappingURL = sourceMappingURL; |
| 126 } | 132 } |
| 127 | 133 |
| 128 void V8DebuggerScript::setSource(v8::Isolate* isolate, | 134 void V8DebuggerScript::setSource(v8::Isolate* isolate, |
| 129 v8::Local<v8::String> source) { | 135 v8::Local<v8::String> source) { |
| 130 m_source.Reset(isolate, source); | 136 m_source.Reset(isolate, source); |
| 131 m_hash = calculateHash(toProtocolString(source)); | 137 m_hash = calculateHash(toProtocolString(source)); |
| 132 } | 138 } |
| 133 | 139 |
| 134 } // namespace v8_inspector | 140 } // namespace v8_inspector |
| OLD | NEW |