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 "wtf/RawPtr.h" | 37 #include "wtf/RawPtr.h" |
38 #include "wtf/text/AtomicString.h" | 38 #include "wtf/text/AtomicString.h" |
39 #include <v8.h> | 39 #include <v8.h> |
40 | 40 |
41 namespace blink { | 41 namespace blink { |
42 | 42 |
43 class Node; | 43 class Node; |
44 struct WrapperTypeInfo; | 44 struct WrapperTypeInfo; |
45 | 45 |
46 class V8DOMWrapper { | 46 class V8DOMWrapper { |
| 47 STATIC_ONLY(V8DOMWrapper); |
47 public: | 48 public: |
48 static v8::Local<v8::Object> createWrapper(v8::Isolate*, v8::Local<v8::Objec
t> creationContext, const WrapperTypeInfo*, ScriptWrappable*); | 49 static v8::Local<v8::Object> createWrapper(v8::Isolate*, v8::Local<v8::Objec
t> creationContext, const WrapperTypeInfo*, ScriptWrappable*); |
49 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); | 50 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); |
50 | 51 |
51 // Associates the given ScriptWrappable with the given |wrapper| if the | 52 // Associates the given ScriptWrappable with the given |wrapper| if the |
52 // ScriptWrappable is not yet associated with any wrapper. Returns the | 53 // ScriptWrappable is not yet associated with any wrapper. Returns the |
53 // wrapper already associated or |wrapper| if not yet associated. | 54 // wrapper already associated or |wrapper| if not yet associated. |
54 // The caller should always use the returned value rather than |wrapper|. | 55 // The caller should always use the returned value rather than |wrapper|. |
55 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Script
Wrappable*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_R
ETURN; | 56 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Script
Wrappable*, const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_R
ETURN; |
56 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Node*,
const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; | 57 static v8::Local<v8::Object> associateObjectWithWrapper(v8::Isolate*, Node*,
const WrapperTypeInfo*, v8::Local<v8::Object> wrapper) WARN_UNUSED_RETURN; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { | 99 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) { |
99 wrapperTypeInfo->refObject(ScriptWrappable::fromNode(node)); | 100 wrapperTypeInfo->refObject(ScriptWrappable::fromNode(node)); |
100 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node))
; | 101 setNativeInfo(wrapper, wrapperTypeInfo, ScriptWrappable::fromNode(node))
; |
101 ASSERT(hasInternalFieldsSet(wrapper)); | 102 ASSERT(hasInternalFieldsSet(wrapper)); |
102 } | 103 } |
103 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(toScriptWrappable(wrapper) == Scrip
tWrappable::fromNode(node)); | 104 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(toScriptWrappable(wrapper) == Scrip
tWrappable::fromNode(node)); |
104 return wrapper; | 105 return wrapper; |
105 } | 106 } |
106 | 107 |
107 class V8WrapperInstantiationScope { | 108 class V8WrapperInstantiationScope { |
| 109 STACK_ALLOCATED(); |
108 public: | 110 public: |
109 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola
te* isolate) | 111 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, v8::Isola
te* isolate) |
110 : m_didEnterContext(false) | 112 : m_didEnterContext(false) |
111 , m_context(isolate->GetCurrentContext()) | 113 , m_context(isolate->GetCurrentContext()) |
112 { | 114 { |
113 // creationContext should not be empty. Because if we have an | 115 // creationContext should not be empty. Because if we have an |
114 // empty creationContext, we will end up creating | 116 // empty creationContext, we will end up creating |
115 // a new object in the context currently entered. This is wrong. | 117 // a new object in the context currently entered. This is wrong. |
116 RELEASE_ASSERT(!creationContext.IsEmpty()); | 118 RELEASE_ASSERT(!creationContext.IsEmpty()); |
117 v8::Local<v8::Context> contextForWrapper = creationContext->CreationCont
ext(); | 119 v8::Local<v8::Context> contextForWrapper = creationContext->CreationCont
ext(); |
(...skipping 16 matching lines...) Expand all Loading... |
134 v8::Local<v8::Context> context() const { return m_context; } | 136 v8::Local<v8::Context> context() const { return m_context; } |
135 | 137 |
136 private: | 138 private: |
137 bool m_didEnterContext; | 139 bool m_didEnterContext; |
138 v8::Local<v8::Context> m_context; | 140 v8::Local<v8::Context> m_context; |
139 }; | 141 }; |
140 | 142 |
141 } // namespace blink | 143 } // namespace blink |
142 | 144 |
143 #endif // V8DOMWrapper_h | 145 #endif // V8DOMWrapper_h |
OLD | NEW |