| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 V8PerContextDataHolder* holder = static_cast<V8PerContextDataHolder*>(co
ntext->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex)); | 61 V8PerContextDataHolder* holder = static_cast<V8PerContextDataHolder*>(co
ntext->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex)); |
| 62 // V8PerContextDataHolder::from() must not be called for a context that
does not have | 62 // V8PerContextDataHolder::from() must not be called for a context that
does not have |
| 63 // valid embedder data in the embedder field. | 63 // valid embedder data in the embedder field. |
| 64 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(holder); | 64 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(holder); |
| 65 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(holder->context() == context); | 65 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(holder->context() == context); |
| 66 return holder; | 66 return holder; |
| 67 } | 67 } |
| 68 | 68 |
| 69 V8PerContextData* perContextData() const { return m_perContextData; } | 69 V8PerContextData* perContextData() const { return m_perContextData; } |
| 70 void setPerContextData(V8PerContextData* data) { m_perContextData = data; } | 70 void setPerContextData(V8PerContextData* data) { m_perContextData = data; } |
| 71 DOMWrapperWorld* world() const { return m_world.get(); } | 71 DOMWrapperWorld& world() const { return *m_world; } |
| 72 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } | 72 v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolat
e); } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 V8PerContextDataHolder(v8::Handle<v8::Context> context, PassRefPtr<DOMWrappe
rWorld> world) | 75 V8PerContextDataHolder(v8::Handle<v8::Context> context, PassRefPtr<DOMWrappe
rWorld> world) |
| 76 : m_isolate(context->GetIsolate()) | 76 : m_isolate(context->GetIsolate()) |
| 77 , m_context(m_isolate, context) | 77 , m_context(m_isolate, context) |
| 78 , m_perContextData(0) | 78 , m_perContextData(0) |
| 79 , m_world(world) | 79 , m_world(world) |
| 80 { | 80 { |
| 81 ASSERT(m_world); |
| 81 m_context.setWeak(this, &V8PerContextDataHolder::weakCallback); | 82 m_context.setWeak(this, &V8PerContextDataHolder::weakCallback); |
| 82 context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, t
his); | 83 context->SetAlignedPointerInEmbedderData(v8ContextPerContextDataIndex, t
his); |
| 83 } | 84 } |
| 84 | 85 |
| 85 ~V8PerContextDataHolder() { } | 86 ~V8PerContextDataHolder() { } |
| 86 | 87 |
| 87 static void weakCallback(const v8::WeakCallbackData<v8::Context, V8PerContex
tDataHolder>& data) | 88 static void weakCallback(const v8::WeakCallbackData<v8::Context, V8PerContex
tDataHolder>& data) |
| 88 { | 89 { |
| 89 data.GetValue()->SetAlignedPointerInEmbedderData(v8ContextPerContextData
Index, 0); | 90 data.GetValue()->SetAlignedPointerInEmbedderData(v8ContextPerContextData
Index, 0); |
| 90 delete data.GetParameter(); | 91 delete data.GetParameter(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 | 124 |
| 124 disposeMapWithUnsafePersistentValues(&m_wrapperBoilerplates); | 125 disposeMapWithUnsafePersistentValues(&m_wrapperBoilerplates); |
| 125 disposeMapWithUnsafePersistentValues(&m_constructorMap); | 126 disposeMapWithUnsafePersistentValues(&m_constructorMap); |
| 126 } | 127 } |
| 127 | 128 |
| 128 V8PerContextData* V8PerContextData::from(v8::Handle<v8::Context> context) | 129 V8PerContextData* V8PerContextData::from(v8::Handle<v8::Context> context) |
| 129 { | 130 { |
| 130 return V8PerContextDataHolder::from(context)->perContextData(); | 131 return V8PerContextDataHolder::from(context)->perContextData(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 DOMWrapperWorld* V8PerContextData::world(v8::Handle<v8::Context> context) | 134 DOMWrapperWorld& V8PerContextData::world(v8::Handle<v8::Context> context) |
| 134 { | 135 { |
| 135 DOMWrapperWorld* world = V8PerContextDataHolder::from(context)->world(); | 136 DOMWrapperWorld& world = V8PerContextDataHolder::from(context)->world(); |
| 136 ASSERT(world); | |
| 137 return world; | 137 return world; |
| 138 } | 138 } |
| 139 | 139 |
| 140 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) | 140 v8::Local<v8::Object> V8PerContextData::createWrapperFromCacheSlowCase(const Wra
pperTypeInfo* type) |
| 141 { | 141 { |
| 142 ASSERT(!m_errorPrototype.isEmpty()); | 142 ASSERT(!m_errorPrototype.isEmpty()); |
| 143 | 143 |
| 144 v8::Context::Scope scope(context()); | 144 v8::Context::Scope scope(context()); |
| 145 v8::Local<v8::Function> function = constructorForType(type); | 145 v8::Local<v8::Function> function = constructorForType(type); |
| 146 v8::Local<v8::Object> instanceTemplate = V8ObjectConstructor::newInstance(fu
nction); | 146 v8::Local<v8::Object> instanceTemplate = V8ObjectConstructor::newInstance(fu
nction); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 if (!data->IsString()) | 260 if (!data->IsString()) |
| 261 return -1; | 261 return -1; |
| 262 v8::String::Utf8Value utf8(data); | 262 v8::String::Utf8Value utf8(data); |
| 263 char* comma = strnstr(*utf8, ",", utf8.length()); | 263 char* comma = strnstr(*utf8, ",", utf8.length()); |
| 264 if (!comma) | 264 if (!comma) |
| 265 return -1; | 265 return -1; |
| 266 return atoi(comma + 1); | 266 return atoi(comma + 1); |
| 267 } | 267 } |
| 268 | 268 |
| 269 } // namespace WebCore | 269 } // namespace WebCore |
| OLD | NEW |