| OLD | NEW |
| 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 "bindings/core/v8/V8HiddenValue.h" | 5 #include "bindings/core/v8/V8HiddenValue.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
| 8 #include "bindings/core/v8/ScriptWrappable.h" | 8 #include "bindings/core/v8/ScriptWrappable.h" |
| 9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 10 | 10 |
| 11 namespace blink { | 11 namespace blink { |
| 12 | 12 |
| 13 #define V8_DEFINE_METHOD(name) \ | |
| 14 v8::Local<v8::String> V8HiddenValue::name(v8::Isolate* isolate) { \ | |
| 15 V8HiddenValue* hiddenValue = \ | |
| 16 V8PerIsolateData::from(isolate)->hiddenValue(); \ | |
| 17 if (hiddenValue->m_##name.isEmpty()) { \ | |
| 18 hiddenValue->m_##name.set(isolate, v8AtomicString(isolate, #name)); \ | |
| 19 } \ | |
| 20 return hiddenValue->m_##name.newLocal(isolate); \ | |
| 21 } | |
| 22 | |
| 23 V8_HIDDEN_VALUES(V8_DEFINE_METHOD); | |
| 24 | |
| 25 v8::Local<v8::Value> V8HiddenValue::getHiddenValue(ScriptState* scriptState, | 13 v8::Local<v8::Value> V8HiddenValue::getHiddenValue(ScriptState* scriptState, |
| 26 v8::Local<v8::Object> object, | 14 v8::Local<v8::Object> object, |
| 27 v8::Local<v8::String> key) { | 15 v8::Local<v8::String> key) { |
| 28 v8::Local<v8::Context> context = scriptState->context(); | 16 v8::Local<v8::Context> context = scriptState->context(); |
| 29 v8::Local<v8::Private> privateKey = | 17 v8::Local<v8::Private> privateKey = |
| 30 v8::Private::ForApi(scriptState->isolate(), key); | 18 v8::Private::ForApi(scriptState->isolate(), key); |
| 31 v8::Local<v8::Value> value; | 19 v8::Local<v8::Value> value; |
| 32 // Callsites interpret an empty handle has absence of a result. | 20 // Callsites interpret an empty handle has absence of a result. |
| 33 if (!v8CallBoolean(object->HasPrivate(context, privateKey))) | 21 if (!v8CallBoolean(object->HasPrivate(context, privateKey))) |
| 34 return v8::Local<v8::Value>(); | 22 return v8::Local<v8::Value>(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 v8::Local<v8::Object> object, | 40 v8::Local<v8::Object> object, |
| 53 v8::Local<v8::String> key) { | 41 v8::Local<v8::String> key) { |
| 54 // Actually deleting the value would make force the object into dictionary | 42 // Actually deleting the value would make force the object into dictionary |
| 55 // mode which is unnecessarily slow. Instead, we replace the hidden value with | 43 // mode which is unnecessarily slow. Instead, we replace the hidden value with |
| 56 // "undefined". | 44 // "undefined". |
| 57 return v8CallBoolean(object->SetPrivate( | 45 return v8CallBoolean(object->SetPrivate( |
| 58 scriptState->context(), v8::Private::ForApi(scriptState->isolate(), key), | 46 scriptState->context(), v8::Private::ForApi(scriptState->isolate(), key), |
| 59 v8::Undefined(scriptState->isolate()))); | 47 v8::Undefined(scriptState->isolate()))); |
| 60 } | 48 } |
| 61 | 49 |
| 62 v8::Local<v8::Value> V8HiddenValue::getHiddenValueFromMainWorldWrapper( | |
| 63 ScriptState* scriptState, | |
| 64 ScriptWrappable* wrappable, | |
| 65 v8::Local<v8::String> key) { | |
| 66 v8::Local<v8::Object> wrapper = | |
| 67 wrappable->mainWorldWrapper(scriptState->isolate()); | |
| 68 return wrapper.IsEmpty() ? v8::Local<v8::Value>() | |
| 69 : getHiddenValue(scriptState, wrapper, key); | |
| 70 } | |
| 71 | |
| 72 } // namespace blink | 50 } // namespace blink |
| OLD | NEW |