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 26 matching lines...) Expand all Loading... |
37 #include "bindings/v8/V8Binding.h" | 37 #include "bindings/v8/V8Binding.h" |
38 #include "bindings/v8/V8HiddenPropertyName.h" | 38 #include "bindings/v8/V8HiddenPropertyName.h" |
39 #include "bindings/v8/V8ObjectConstructor.h" | 39 #include "bindings/v8/V8ObjectConstructor.h" |
40 #include "bindings/v8/V8PerContextData.h" | 40 #include "bindings/v8/V8PerContextData.h" |
41 #include "bindings/v8/V8ScriptRunner.h" | 41 #include "bindings/v8/V8ScriptRunner.h" |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 class V8WrapperInstantiationScope { | 45 class V8WrapperInstantiationScope { |
46 public: | 46 public: |
47 explicit V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext) | 47 V8WrapperInstantiationScope(v8::Handle<v8::Object> creationContext, v8::Isol
ate* isolate) |
48 : m_didEnterContext(false) | 48 : m_didEnterContext(false) |
49 , m_context(v8::Context::GetCurrent()) | 49 , m_context(v8::Context::GetCurrent()) |
50 { | 50 { |
51 // FIXME: Remove all empty creationContexts from caller sites. | 51 // FIXME: Remove all empty creationContexts from caller sites. |
52 // If a creationContext is empty, we will end up creating a new object | 52 // If a creationContext is empty, we will end up creating a new object |
53 // in the context currently entered. This is wrong. | 53 // in the context currently entered. This is wrong. |
54 if (creationContext.IsEmpty()) | 54 if (creationContext.IsEmpty()) |
55 return; | 55 return; |
56 v8::Handle<v8::Context> contextForWrapper = creationContext->CreationCon
text(); | 56 v8::Handle<v8::Context> contextForWrapper = creationContext->CreationCon
text(); |
57 // For performance, we enter the context only if the currently running c
ontext | 57 // For performance, we enter the context only if the currently running c
ontext |
58 // is different from the context that we are about to enter. | 58 // is different from the context that we are about to enter. |
59 if (contextForWrapper == m_context) | 59 if (contextForWrapper == m_context) |
60 return; | 60 return; |
61 m_context = v8::Local<v8::Context>::New(contextForWrapper); | 61 m_context = v8::Local<v8::Context>::New(isolate, contextForWrapper); |
62 m_didEnterContext = true; | 62 m_didEnterContext = true; |
63 m_context->Enter(); | 63 m_context->Enter(); |
64 } | 64 } |
65 | 65 |
66 ~V8WrapperInstantiationScope() | 66 ~V8WrapperInstantiationScope() |
67 { | 67 { |
68 if (!m_didEnterContext) | 68 if (!m_didEnterContext) |
69 return; | 69 return; |
70 m_context->Exit(); | 70 m_context->Exit(); |
71 } | 71 } |
(...skipping 29 matching lines...) Expand all Loading... |
101 v8::Local<v8::Object> shadow = V8ScriptRunner::instantiateObject(shadowConst
ructor); | 101 v8::Local<v8::Object> shadow = V8ScriptRunner::instantiateObject(shadowConst
ructor); |
102 if (shadow.IsEmpty()) | 102 if (shadow.IsEmpty()) |
103 return v8::Local<v8::Object>(); | 103 return v8::Local<v8::Object>(); |
104 shadow->SetPrototype(wrapper); | 104 shadow->SetPrototype(wrapper); |
105 V8DOMWrapper::setNativeInfo(wrapper, &V8HTMLDocument::info, impl); | 105 V8DOMWrapper::setNativeInfo(wrapper, &V8HTMLDocument::info, impl); |
106 return shadow; | 106 return shadow; |
107 } | 107 } |
108 | 108 |
109 v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Handle<v8::Object> creatio
nContext, WrapperTypeInfo* type, void* impl, v8::Isolate* isolate) | 109 v8::Local<v8::Object> V8DOMWrapper::createWrapper(v8::Handle<v8::Object> creatio
nContext, WrapperTypeInfo* type, void* impl, v8::Isolate* isolate) |
110 { | 110 { |
111 V8WrapperInstantiationScope scope(creationContext); | 111 V8WrapperInstantiationScope scope(creationContext, isolate); |
112 | 112 |
113 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); | 113 V8PerContextData* perContextData = V8PerContextData::from(scope.context()); |
114 v8::Local<v8::Object> wrapper = perContextData ? perContextData->createWrapp
erFromCache(type) : V8ObjectConstructor::newInstance(type->getTemplate(isolate,
worldTypeInMainThread(isolate))->GetFunction()); | 114 v8::Local<v8::Object> wrapper = perContextData ? perContextData->createWrapp
erFromCache(type) : V8ObjectConstructor::newInstance(type->getTemplate(isolate,
worldTypeInMainThread(isolate))->GetFunction()); |
115 | 115 |
116 if (type == &V8HTMLDocument::info && !wrapper.IsEmpty()) | 116 if (type == &V8HTMLDocument::info && !wrapper.IsEmpty()) |
117 wrapper = wrapInShadowTemplate(wrapper, static_cast<Node*>(impl), isolat
e); | 117 wrapper = wrapInShadowTemplate(wrapper, static_cast<Node*>(impl), isolat
e); |
118 | 118 |
119 return wrapper; | 119 return wrapper; |
120 } | 120 } |
121 | 121 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value); | 165 v8::Handle<v8::Object> wrapper = v8::Handle<v8::Object>::Cast(value); |
166 ASSERT(wrapper->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount); | 166 ASSERT(wrapper->InternalFieldCount() >= v8DefaultWrapperInternalFieldCount); |
167 ASSERT(wrapper->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex))
; | 167 ASSERT(wrapper->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex))
; |
168 | 168 |
169 WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(wrapper->GetAligne
dPointerFromInternalField(v8DOMWrapperTypeIndex)); | 169 WrapperTypeInfo* typeInfo = static_cast<WrapperTypeInfo*>(wrapper->GetAligne
dPointerFromInternalField(v8DOMWrapperTypeIndex)); |
170 return typeInfo == type; | 170 return typeInfo == type; |
171 } | 171 } |
172 | 172 |
173 } // namespace WebCore | 173 } // namespace WebCore |
OLD | NEW |