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

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

Issue 537403002: bindings: Renames from/toInternalPointer, etc. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Synced. Created 6 years, 3 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/core/v8/ScriptProfiler.cpp ('k') | Source/bindings/core/v8/ScriptWrappable.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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // This doesn't happen with other compilers which support EBCO. All the 71 // This doesn't happen with other compilers which support EBCO. All the
72 // addresses in the above example will be 0x1000 with EBCO supported. 72 // addresses in the above example will be 0x1000 with EBCO supported.
73 // 73 //
74 // Since v8::Object::SetAlignedPointerInInternalField requires the pointers to 74 // Since v8::Object::SetAlignedPointerInInternalField requires the pointers to
75 // be aligned, we need a hack to specify at least 4 byte alignment to MSVC. 75 // be aligned, we need a hack to specify at least 4 byte alignment to MSVC.
76 __declspec(align(4)) 76 __declspec(align(4))
77 #endif 77 #endif
78 class ScriptWrappableBase { 78 class ScriptWrappableBase {
79 public: 79 public:
80 template<typename T> 80 template<typename T>
81 static T* fromInternalPointer(ScriptWrappableBase* internalPointer) 81 T* toImpl()
82 { 82 {
83 // Check if T* is castable to ScriptWrappableBase*, which means T 83 // Check if T* is castable to ScriptWrappableBase*, which means T
84 // doesn't have two or more ScriptWrappableBase as superclasses. 84 // doesn't have two or more ScriptWrappableBase as superclasses.
85 // If T has two ScriptWrappableBase as superclasses, conversions 85 // If T has two ScriptWrappableBase as superclasses, conversions
86 // from T* to ScriptWrappableBase* are ambiguous. 86 // from T* to ScriptWrappableBase* are ambiguous.
87 ASSERT(static_cast<ScriptWrappableBase*>(static_cast<T*>(internalPointer ))); 87 ASSERT(static_cast<ScriptWrappableBase*>(static_cast<T*>(this)));
88 // The internal pointers must be aligned to at least 4 byte alignment. 88 // The internal pointers must be aligned to at least 4 byte alignment.
89 ASSERT((reinterpret_cast<intptr_t>(internalPointer) & 0x3) == 0); 89 ASSERT((reinterpret_cast<intptr_t>(this) & 0x3) == 0);
90 return static_cast<T*>(internalPointer); 90 return static_cast<T*>(this);
91 } 91 }
92 ScriptWrappableBase* toInternalPointer() 92 ScriptWrappableBase* toScriptWrappableBase()
93 { 93 {
94 // The internal pointers must be aligned to at least 4 byte alignment. 94 // The internal pointers must be aligned to at least 4 byte alignment.
95 ASSERT((reinterpret_cast<intptr_t>(this) & 0x3) == 0); 95 ASSERT((reinterpret_cast<intptr_t>(this) & 0x3) == 0);
96 return this; 96 return this;
97 } 97 }
98 98
99 void assertWrapperSanity(v8::Local<v8::Object> object) 99 void assertWrapperSanity(v8::Local<v8::Object> object)
100 { 100 {
101 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(object.IsEmpty() 101 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(object.IsEmpty()
102 || object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectInde x) == toInternalPointer()); 102 || object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectInde x) == toScriptWrappableBase());
103 } 103 }
104 }; 104 };
105 105
106 /** 106 /**
107 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo. 107 * ScriptWrappable wraps a V8 object and its WrapperTypeInfo.
108 * 108 *
109 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a 109 * ScriptWrappable acts much like a v8::Persistent<> in that it keeps a
110 * V8 object alive. Under the hood, however, it keeps either a TypeInfo 110 * V8 object alive. Under the hood, however, it keeps either a TypeInfo
111 * object or an actual v8 persistent (or is empty). 111 * object or an actual v8 persistent (or is empty).
112 * 112 *
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 v8::Persistent<v8::Object> persistent; 243 v8::Persistent<v8::Object> persistent;
244 getPersistent(&persistent); 244 getPersistent(&persistent);
245 isolate->SetReference(parent, persistent); 245 isolate->SetReference(parent, persistent);
246 } 246 }
247 247
248 template<typename V8T, typename T> 248 template<typename V8T, typename T>
249 static void assertWrapperSanity(v8::Local<v8::Object> object, T* objectAsT) 249 static void assertWrapperSanity(v8::Local<v8::Object> object, T* objectAsT)
250 { 250 {
251 ASSERT(objectAsT); 251 ASSERT(objectAsT);
252 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(object.IsEmpty() 252 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(object.IsEmpty()
253 || object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectInde x) == V8T::toInternalPointer(objectAsT)); 253 || object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectInde x) == V8T::toScriptWrappableBase(objectAsT));
254 } 254 }
255 255
256 template<typename V8T, typename T> 256 template<typename V8T, typename T>
257 static void assertWrapperSanity(void* object, T* objectAsT) 257 static void assertWrapperSanity(void* object, T* objectAsT)
258 { 258 {
259 ASSERT_NOT_REACHED(); 259 ASSERT_NOT_REACHED();
260 } 260 }
261 261
262 template<typename V8T, typename T> 262 template<typename V8T, typename T>
263 static void assertWrapperSanity(ScriptWrappable* object, T* objectAsT) 263 static void assertWrapperSanity(ScriptWrappable* object, T* objectAsT)
264 { 264 {
265 ASSERT(object); 265 ASSERT(object);
266 ASSERT(objectAsT); 266 ASSERT(objectAsT);
267 v8::Object* value = object->getRawValue(); 267 v8::Object* value = object->getRawValue();
268 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(value == 0 268 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(value == 0
269 || value->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex ) == V8T::toInternalPointer(objectAsT)); 269 || value->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex ) == V8T::toScriptWrappableBase(objectAsT));
270 } 270 }
271 271
272 using ScriptWrappableBase::assertWrapperSanity; 272 using ScriptWrappableBase::assertWrapperSanity;
273 273
274 inline bool containsWrapper() const { return (m_wrapperOrTypeInfo & 1); } 274 inline bool containsWrapper() const { return (m_wrapperOrTypeInfo & 1); }
275 inline bool containsTypeInfo() const { return m_wrapperOrTypeInfo && !(m_wra pperOrTypeInfo & 1); } 275 inline bool containsTypeInfo() const { return m_wrapperOrTypeInfo && !(m_wra pperOrTypeInfo & 1); }
276 276
277 #if !ENABLE(OILPAN) 277 #if !ENABLE(OILPAN)
278 protected: 278 protected:
279 virtual ~ScriptWrappable() 279 virtual ~ScriptWrappable()
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 virtual const WrapperTypeInfo* wrapperTypeInfo() const OVERRIDE \ 366 virtual const WrapperTypeInfo* wrapperTypeInfo() const OVERRIDE \
367 { \ 367 { \
368 return &s_wrapperTypeInfo; \ 368 return &s_wrapperTypeInfo; \
369 } \ 369 } \
370 private: \ 370 private: \
371 static const WrapperTypeInfo& s_wrapperTypeInfo 371 static const WrapperTypeInfo& s_wrapperTypeInfo
372 372
373 } // namespace blink 373 } // namespace blink
374 374
375 #endif // ScriptWrappable_h 375 #endif // ScriptWrappable_h
OLDNEW
« no previous file with comments | « Source/bindings/core/v8/ScriptProfiler.cpp ('k') | Source/bindings/core/v8/ScriptWrappable.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698