OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/V8ValueCopier.h" | 5 #include "platform/v8_inspector/V8ValueCopier.h" |
6 | 6 |
7 namespace v8_inspector { | 7 namespace v8_inspector { |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 v8::Local<v8::Array> result = v8::Array::New(m_isolate, array->Lengt
h()); | 33 v8::Local<v8::Array> result = v8::Array::New(m_isolate, array->Lengt
h()); |
34 if (!result->SetPrototype(m_to, v8::Null(m_isolate)).FromMaybe(false
)) | 34 if (!result->SetPrototype(m_to, v8::Null(m_isolate)).FromMaybe(false
)) |
35 return v8::MaybeLocal<v8::Value>(); | 35 return v8::MaybeLocal<v8::Value>(); |
36 for (size_t i = 0; i < array->Length(); ++i) { | 36 for (size_t i = 0; i < array->Length(); ++i) { |
37 v8::Local<v8::Value> item; | 37 v8::Local<v8::Value> item; |
38 if (!array->Get(m_from, i).ToLocal(&item)) | 38 if (!array->Get(m_from, i).ToLocal(&item)) |
39 return v8::MaybeLocal<v8::Value>(); | 39 return v8::MaybeLocal<v8::Value>(); |
40 v8::Local<v8::Value> copied; | 40 v8::Local<v8::Value> copied; |
41 if (!copy(item, depth + 1).ToLocal(&copied)) | 41 if (!copy(item, depth + 1).ToLocal(&copied)) |
42 return v8::MaybeLocal<v8::Value>(); | 42 return v8::MaybeLocal<v8::Value>(); |
43 if (!result->Set(m_to, i, copied).FromMaybe(false)) | 43 if (!createDataProperty(m_to, result, i, copied).FromMaybe(false
)) |
44 return v8::MaybeLocal<v8::Value>(); | 44 return v8::MaybeLocal<v8::Value>(); |
45 } | 45 } |
46 return result; | 46 return result; |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 v8::Local<v8::Object> result = v8::Object::New(m_isolate); | 50 v8::Local<v8::Object> result = v8::Object::New(m_isolate); |
51 if (!result->SetPrototype(m_to, v8::Null(m_isolate)).FromMaybe(false)) | 51 if (!result->SetPrototype(m_to, v8::Null(m_isolate)).FromMaybe(false)) |
52 return v8::MaybeLocal<v8::Value>(); | 52 return v8::MaybeLocal<v8::Value>(); |
53 v8::Local<v8::Array> properties; | 53 v8::Local<v8::Array> properties; |
54 if (!object->GetOwnPropertyNames(m_from).ToLocal(&properties)) | 54 if (!object->GetOwnPropertyNames(m_from).ToLocal(&properties)) |
55 return v8::MaybeLocal<v8::Value>(); | 55 return v8::MaybeLocal<v8::Value>(); |
56 for (size_t i = 0; i < properties->Length(); ++i) { | 56 for (size_t i = 0; i < properties->Length(); ++i) { |
57 v8::Local<v8::Value> name; | 57 v8::Local<v8::Value> name; |
58 if (!properties->Get(m_from, i).ToLocal(&name) || !name->IsString()) | 58 if (!properties->Get(m_from, i).ToLocal(&name) || !name->IsString()) |
59 return v8::MaybeLocal<v8::Value>(); | 59 return v8::MaybeLocal<v8::Value>(); |
60 v8::Local<v8::Value> property; | 60 v8::Local<v8::Value> property; |
61 if (!object->Get(m_from, name).ToLocal(&property)) | 61 if (!object->Get(m_from, name).ToLocal(&property)) |
62 return v8::MaybeLocal<v8::Value>(); | 62 return v8::MaybeLocal<v8::Value>(); |
63 v8::Local<v8::Value> copied; | 63 v8::Local<v8::Value> copied; |
64 if (!copy(property, depth + 1).ToLocal(&copied)) | 64 if (!copy(property, depth + 1).ToLocal(&copied)) |
65 return v8::MaybeLocal<v8::Value>(); | 65 return v8::MaybeLocal<v8::Value>(); |
66 if (!result->Set(m_to, name, copied).FromMaybe(false)) | 66 if (!createDataProperty(m_to, result, v8::Local<v8::String>::Cast(na
me), copied).FromMaybe(false)) |
67 return v8::MaybeLocal<v8::Value>(); | 67 return v8::MaybeLocal<v8::Value>(); |
68 } | 68 } |
69 return result; | 69 return result; |
70 } | 70 } |
71 | 71 |
72 v8::Isolate* m_isolate; | 72 v8::Isolate* m_isolate; |
73 v8::Local<v8::Context> m_from; | 73 v8::Local<v8::Context> m_from; |
74 v8::Local<v8::Context> m_to; | 74 v8::Local<v8::Context> m_to; |
75 int m_calls; | 75 int m_calls; |
76 }; | 76 }; |
77 | 77 |
78 } // namespace | 78 } // namespace |
79 | 79 |
80 v8::MaybeLocal<v8::Value> copyValueFromDebuggerContext(v8::Isolate* isolate, v8:
:Local<v8::Context> debuggerContext, v8::Local<v8::Context> toContext, v8::Local
<v8::Value> value) | 80 v8::MaybeLocal<v8::Value> copyValueFromDebuggerContext(v8::Isolate* isolate, v8:
:Local<v8::Context> debuggerContext, v8::Local<v8::Context> toContext, v8::Local
<v8::Value> value) |
81 { | 81 { |
82 V8ValueCopier copier; | 82 V8ValueCopier copier; |
83 copier.m_isolate = isolate; | 83 copier.m_isolate = isolate; |
84 copier.m_from = debuggerContext; | 84 copier.m_from = debuggerContext; |
85 copier.m_to = toContext; | 85 copier.m_to = toContext; |
86 copier.m_calls = 0; | 86 copier.m_calls = 0; |
87 return copier.copy(value, 0); | 87 return copier.copy(value, 0); |
88 } | 88 } |
89 | 89 |
| 90 v8::Maybe<bool> createDataProperty(v8::Local<v8::Context> context, v8::Local<v8:
:Object> object, v8::Local<v8::Name> key, v8::Local<v8::Value> value) |
| 91 { |
| 92 v8::TryCatch tryCatch(context->GetIsolate()); |
| 93 v8::Isolate::DisallowJavascriptExecutionScope throwJs(context->GetIsolate(),
v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 94 return object->CreateDataProperty(context, key, value); |
| 95 } |
| 96 |
| 97 v8::Maybe<bool> createDataProperty(v8::Local<v8::Context> context, v8::Local<v8:
:Array> array, int index, v8::Local<v8::Value> value) |
| 98 { |
| 99 v8::TryCatch tryCatch(context->GetIsolate()); |
| 100 v8::Isolate::DisallowJavascriptExecutionScope throwJs(context->GetIsolate(),
v8::Isolate::DisallowJavascriptExecutionScope::THROW_ON_FAILURE); |
| 101 return array->CreateDataProperty(context, index, value); |
| 102 } |
| 103 |
90 } // namespace v8_inspector | 104 } // namespace v8_inspector |
OLD | NEW |