OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 67 matching lines...) Loading... |
78 template<typename V8T, typename T> | 78 template<typename V8T, typename T> |
79 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassR
efPtr<T> object, const WrapperTypeInfo* type, v8::Handle<v8::Object> wrapper, v8
::Isolate* isolate, WrapperConfiguration::Lifetime lifetime) | 79 inline v8::Handle<v8::Object> V8DOMWrapper::associateObjectWithWrapper(PassR
efPtr<T> object, const WrapperTypeInfo* type, v8::Handle<v8::Object> wrapper, v8
::Isolate* isolate, WrapperConfiguration::Lifetime lifetime) |
80 { | 80 { |
81 setNativeInfo(wrapper, type, V8T::toInternalPointer(object.get())); | 81 setNativeInfo(wrapper, type, V8T::toInternalPointer(object.get())); |
82 ASSERT(maybeDOMWrapper(wrapper)); | 82 ASSERT(maybeDOMWrapper(wrapper)); |
83 WrapperConfiguration configuration = buildWrapperConfiguration(object.ge
t(), lifetime); | 83 WrapperConfiguration configuration = buildWrapperConfiguration(object.ge
t(), lifetime); |
84 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, config
uration); | 84 DOMDataStore::setWrapper<V8T>(object.leakRef(), wrapper, isolate, config
uration); |
85 return wrapper; | 85 return wrapper; |
86 } | 86 } |
87 | 87 |
| 88 class V8WrapperInstantiationScope { |
| 89 public: |
| 90 V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext, v8::
Isolate* isolate) |
| 91 : m_didEnterContext(false) |
| 92 , m_context(v8::Context::GetCurrent()) |
| 93 { |
| 94 // FIXME: Remove all empty creationContexts from caller sites. |
| 95 // If a creationContext is empty, we will end up creating a new obje
ct |
| 96 // in the context currently entered. This is wrong. |
| 97 if (creationContext.IsEmpty()) |
| 98 return; |
| 99 v8::Handle<v8::Context> contextForWrapper = creationContext->Creatio
nContext(); |
| 100 // For performance, we enter the context only if the currently runni
ng context |
| 101 // is different from the context that we are about to enter. |
| 102 if (contextForWrapper == m_context) |
| 103 return; |
| 104 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper); |
| 105 m_didEnterContext = true; |
| 106 m_context->Enter(); |
| 107 } |
| 108 |
| 109 ~V8WrapperInstantiationScope() |
| 110 { |
| 111 if (!m_didEnterContext) |
| 112 return; |
| 113 m_context->Exit(); |
| 114 } |
| 115 |
| 116 v8::Handle<v8::Context> context() const { return m_context; } |
| 117 |
| 118 private: |
| 119 bool m_didEnterContext; |
| 120 v8::Handle<v8::Context> m_context; |
| 121 }; |
| 122 |
88 } | 123 } |
89 | 124 |
90 #endif // V8DOMWrapper_h | 125 #endif // V8DOMWrapper_h |
OLD | NEW |