Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/bindings/core/v8/V8ScriptWrappable.h

Issue 611833004: [multivm] Re-split fields for V8 and Dart wrappers. (Closed) Base URL: svn://svn.chromium.org/blink/branches/dart/multivm
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/bindings/common/ScriptWrappable.h ('k') | Source/bindings/core/v8/V8ScriptWrappable.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 ASSERT(persistent); 42 ASSERT(persistent);
43 // Horrible and super unsafe: Cast the Persistent to an Object*, so 43 // Horrible and super unsafe: Cast the Persistent to an Object*, so
44 // that we can inject the wrapped value. This only works because 44 // that we can inject the wrapped value. This only works because
45 // we previously 'stole' the object pointer from a Persistent in 45 // we previously 'stole' the object pointer from a Persistent in
46 // the setWrapper() method. 46 // the setWrapper() method.
47 *reinterpret_cast<v8::Object**>(persistent) = object; 47 *reinterpret_cast<v8::Object**>(persistent) = object;
48 } 48 }
49 49
50 bool ScriptWrappable::containsV8Wrapper() const 50 bool ScriptWrappable::containsV8Wrapper() const
51 { 51 {
52 if (LIKELY(m_wrapper.isV8WrapperOrEmpty())) { 52 return m_v8Wrapper;
53 return !m_wrapper.isEmpty();
54 }
55 TaggedPointer v8WrapperOrTypeInfo = getV8WrapperOrEmpty();
56 return !v8WrapperOrTypeInfo.isEmpty();
57 } 53 }
58 54
59 // Caller is responsible for putting the type info into the wrapper. 55 // Caller is responsible for putting the type info into the wrapper.
60 void ScriptWrappable::setV8Wrapper(v8::Object* wrapper) 56 void ScriptWrappable::setV8Wrapper(v8::Object* wrapper)
61 { 57 {
62 if (LIKELY(m_wrapper.isEmpty())) { 58 m_v8Wrapper = wrapper;
63 m_wrapper = TaggedPointer(wrapper);
64 } else if (m_wrapper.isDartWrapperInfo()) {
65 ASSERT_NOT_REACHED();
66 DartWrapperInfo* wrapperInfo = m_wrapper.dartWrapperInfo();
67 if (wrapperInfo->v8WrapperOrEmpty.isEmpty()) {
68 wrapperInfo->v8WrapperOrEmpty = TaggedPointer(wrapper);
69 } else {
70 // Already contains V8 wrapper.
71 ASSERT_NOT_REACHED();
72 }
73 } else if (m_wrapper.isDartMultiWrapperInfo()) {
74 DartMultiWrapperInfo* wrapperInfo = m_wrapper.dartMultiWrapperInfo();
75 if (wrapperInfo->v8WrapperOrEmpty.isEmpty()) {
76 wrapperInfo->v8WrapperOrEmpty = TaggedPointer(wrapper);
77 } else {
78 // Already contains V8 wrapper.
79 ASSERT_NOT_REACHED();
80 }
81 } else {
82 // Already contains V8 wrapper.
83 ASSERT_NOT_REACHED();
84 }
85 } 59 }
86 60
87 v8::Object* ScriptWrappable::getV8Wrapper() const 61 v8::Object* ScriptWrappable::getV8Wrapper() const
88 { 62 {
89 if (LIKELY(m_wrapper.isV8WrapperOrEmpty())) { 63 return m_v8Wrapper;
90 return m_wrapper.v8Wrapper();
91 }
92 TaggedPointer v8WrapperOrTypeInfo = getV8WrapperOrEmpty();
93 return v8WrapperOrTypeInfo.v8Wrapper();
94 } 64 }
95 65
96 void ScriptWrappable::clearV8Wrapper(v8::Local<v8::Object> wrapper, v8::Persiste nt<v8::Object>* persistent) 66 void ScriptWrappable::clearV8Wrapper(v8::Local<v8::Object> wrapper, v8::Persiste nt<v8::Object>* persistent)
97 { 67 {
98 if (LIKELY(m_wrapper.isV8Wrapper())) { 68 asV8Persistent(m_v8Wrapper, persistent);
99 asV8Persistent(m_wrapper.v8Wrapper(), persistent); 69 m_v8Wrapper = 0;
100 ASSERT(wrapper == *persistent);
101 m_wrapper.clear();
102 } else if (m_wrapper.isDartWrapperInfo()) {
103 DartWrapperInfo* wrapperInfo = m_wrapper.dartWrapperInfo();
104 if (wrapperInfo->v8WrapperOrEmpty.isV8Wrapper()) {
105 asV8Persistent(wrapperInfo->v8WrapperOrEmpty.v8Wrapper(), persistent );
106 ASSERT(wrapper == *persistent);
107 wrapperInfo->v8WrapperOrEmpty.clear();
108 } else {
109 // Already clear.
110 ASSERT_NOT_REACHED();
111 }
112 } else if (m_wrapper.isDartMultiWrapperInfo()) {
113 DartMultiWrapperInfo* wrapperInfo = m_wrapper.dartMultiWrapperInfo();
114 if (wrapperInfo->v8WrapperOrEmpty.isV8Wrapper()) {
115 asV8Persistent(wrapperInfo->v8WrapperOrEmpty.v8Wrapper(), persistent );
116 ASSERT(wrapper == *persistent);
117 wrapperInfo->v8WrapperOrEmpty.clear();
118 } else {
119 // Already clear.
120 ASSERT_NOT_REACHED();
121 }
122 } else {
123 // Already clear.
124 ASSERT_NOT_REACHED();
125 }
126 } 70 }
127 71
128 /** 72 /**
129 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. 73 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo.
130 * 74 *
131 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a 75 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a
132 * V8 object alive. Under the hood, however, it keeps either a TypeInfo 76 * V8 object alive. Under the hood, however, it keeps either a TypeInfo
133 * object or an actual v8 persistent (or is empty). 77 * object or an actual v8 persistent (or is empty).
134 * 78 *
135 * The physical state space of ScriptWrappable is: 79 * The physical state space of ScriptWrappable is:
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 virtual const WrapperTypeInfo* wrapperTypeInfo() const OVERRIDE \ 229 virtual const WrapperTypeInfo* wrapperTypeInfo() const OVERRIDE \
286 { \ 230 { \
287 return &s_wrapperTypeInfo; \ 231 return &s_wrapperTypeInfo; \
288 } \ 232 } \
289 private: \ 233 private: \
290 static const WrapperTypeInfo& s_wrapperTypeInfo 234 static const WrapperTypeInfo& s_wrapperTypeInfo
291 235
292 } // namespace blink 236 } // namespace blink
293 237
294 #endif // V8ScriptWrappable_h 238 #endif // V8ScriptWrappable_h
OLDNEW
« no previous file with comments | « Source/bindings/common/ScriptWrappable.h ('k') | Source/bindings/core/v8/V8ScriptWrappable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698