| 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 "bindings/core/v8/V8PrivateProperty.h" | 5 #include "bindings/core/v8/V8PrivateProperty.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 #include "bindings/core/v8/V8BindingMacros.h" | 10 #include "bindings/core/v8/V8BindingMacros.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 void V8PrivateProperty::initialize(v8::Isolate* isolate, SymbolID symbolID) { |
| 15 static const char* const kSymbolNames[] = { |
| 16 #define PRIVATE_PROPERTY_STRING(InterfaceName, PrivateKeyName) \ |
| 17 V8_PRIVATE_PROPERTY_SYMBOL_STRING(InterfaceName, PrivateKeyName), |
| 18 V8_PRIVATE_PROPERTY_FOR_EACH(PRIVATE_PROPERTY_STRING) |
| 19 #undef PRIVATE_PROPERTY_STRING |
| 20 }; |
| 21 const char* symbolName = kSymbolNames[symbolID]; |
| 22 m_symbols[symbolID].Set( |
| 23 isolate, createV8Private(isolate, symbolName, strlen(symbolName))); |
| 24 } |
| 25 |
| 14 v8::Local<v8::Value> V8PrivateProperty::Symbol::getFromMainWorld( | 26 v8::Local<v8::Value> V8PrivateProperty::Symbol::getFromMainWorld( |
| 15 ScriptState* scriptState, | 27 ScriptState* scriptState, |
| 16 ScriptWrappable* scriptWrappable) { | 28 ScriptWrappable* scriptWrappable) { |
| 17 v8::Local<v8::Object> wrapper = | 29 v8::Local<v8::Object> wrapper = |
| 18 scriptWrappable->mainWorldWrapper(scriptState->isolate()); | 30 scriptWrappable->mainWorldWrapper(scriptState->isolate()); |
| 19 return wrapper.IsEmpty() ? v8::Local<v8::Value>() | 31 return wrapper.IsEmpty() ? v8::Local<v8::Value>() |
| 20 : get(scriptState->context(), wrapper); | 32 : get(scriptState->context(), wrapper); |
| 21 } | 33 } |
| 22 | 34 |
| 23 v8::Local<v8::Private> V8PrivateProperty::createV8Private(v8::Isolate* isolate, | 35 v8::Local<v8::Private> V8PrivateProperty::createV8Private(v8::Isolate* isolate, |
| 24 const char* symbol, | 36 const char* symbol, |
| 25 size_t length) { | 37 size_t length) { |
| 26 v8::Local<v8::String> str = | 38 v8::Local<v8::String> str = |
| 27 v8::String::NewFromOneByte( | 39 v8::String::NewFromOneByte( |
| 28 isolate, reinterpret_cast<const uint8_t*>(symbol), | 40 isolate, reinterpret_cast<const uint8_t*>(symbol), |
| 29 v8::NewStringType::kNormal, static_cast<int>(length)) | 41 v8::NewStringType::kNormal, static_cast<int>(length)) |
| 30 .ToLocalChecked(); | 42 .ToLocalChecked(); |
| 31 return v8::Private::New(isolate, str); | 43 return v8::Private::New(isolate, str); |
| 32 } | 44 } |
| 33 | 45 |
| 34 } // namespace blink | 46 } // namespace blink |
| OLD | NEW |