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

Side by Side Diff: third_party/WebKit/Source/bindings/core/v8/V8DOMWrapper.h

Issue 2726593002: Use mayNotBeMainThread() for wrapper optimization (Closed)
Patch Set: Use V8TestingScope Created 3 years, 9 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
OLDNEW
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 24 matching lines...) Expand all
35 #include "bindings/core/v8/DOMDataStore.h" 35 #include "bindings/core/v8/DOMDataStore.h"
36 #include "bindings/core/v8/ScriptWrappable.h" 36 #include "bindings/core/v8/ScriptWrappable.h"
37 #include "bindings/core/v8/V8Binding.h" 37 #include "bindings/core/v8/V8Binding.h"
38 #include "core/CoreExport.h" 38 #include "core/CoreExport.h"
39 #include "v8/include/v8.h" 39 #include "v8/include/v8.h"
40 #include "wtf/Compiler.h" 40 #include "wtf/Compiler.h"
41 #include "wtf/text/AtomicString.h" 41 #include "wtf/text/AtomicString.h"
42 42
43 namespace blink { 43 namespace blink {
44 44
45 class Node;
46 struct WrapperTypeInfo; 45 struct WrapperTypeInfo;
47 46
48 class V8DOMWrapper { 47 class V8DOMWrapper {
49 STATIC_ONLY(V8DOMWrapper); 48 STATIC_ONLY(V8DOMWrapper);
50 49
51 public: 50 public:
52 static v8::Local<v8::Object> createWrapper( 51 static v8::Local<v8::Object> createWrapper(
53 v8::Isolate*, 52 v8::Isolate*,
54 v8::Local<v8::Object> creationContext, 53 v8::Local<v8::Object> creationContext,
55 const WrapperTypeInfo*); 54 const WrapperTypeInfo*);
56 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>); 55 static bool isWrapper(v8::Isolate*, v8::Local<v8::Value>);
57 56
58 // Associates the given ScriptWrappable with the given |wrapper| if the 57 // Associates the given ScriptWrappable with the given |wrapper| if the
59 // ScriptWrappable is not yet associated with any wrapper. Returns the 58 // ScriptWrappable is not yet associated with any wrapper. Returns the
60 // wrapper already associated or |wrapper| if not yet associated. 59 // wrapper already associated or |wrapper| if not yet associated.
61 // The caller should always use the returned value rather than |wrapper|. 60 // The caller should always use the returned value rather than |wrapper|.
62 WARN_UNUSED_RESULT static v8::Local<v8::Object> associateObjectWithWrapper( 61 WARN_UNUSED_RESULT static v8::Local<v8::Object> associateObjectWithWrapper(
63 v8::Isolate*, 62 v8::Isolate*,
64 ScriptWrappable*, 63 ScriptWrappable*,
65 const WrapperTypeInfo*, 64 const WrapperTypeInfo*,
66 v8::Local<v8::Object> wrapper); 65 v8::Local<v8::Object> wrapper);
67 WARN_UNUSED_RESULT static v8::Local<v8::Object> associateObjectWithWrapper(
68 v8::Isolate*,
69 Node*,
70 const WrapperTypeInfo*,
71 v8::Local<v8::Object> wrapper);
72 static void setNativeInfo(v8::Isolate*, 66 static void setNativeInfo(v8::Isolate*,
73 v8::Local<v8::Object>, 67 v8::Local<v8::Object>,
74 const WrapperTypeInfo*, 68 const WrapperTypeInfo*,
75 ScriptWrappable*); 69 ScriptWrappable*);
76 static void clearNativeInfo(v8::Isolate*, v8::Local<v8::Object>); 70 static void clearNativeInfo(v8::Isolate*, v8::Local<v8::Object>);
77 71
78 // hasInternalFieldsSet only checks if the value has the internal fields for 72 // hasInternalFieldsSet only checks if the value has the internal fields for
79 // wrapper obejct and type, and does not check if it's valid or not. The 73 // wrapper obejct and type, and does not check if it's valid or not. The
80 // value may not be a Blink's wrapper object. In order to make sure of it, 74 // value may not be a Blink's wrapper object. In order to make sure of it,
81 // Use isWrapper function instead. 75 // Use isWrapper function instead.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 v8::Local<v8::Object> wrapper) { 112 v8::Local<v8::Object> wrapper) {
119 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) { 113 if (DOMDataStore::setWrapper(isolate, impl, wrapperTypeInfo, wrapper)) {
120 wrapperTypeInfo->wrapperCreated(); 114 wrapperTypeInfo->wrapperCreated();
121 setNativeInfo(isolate, wrapper, wrapperTypeInfo, impl); 115 setNativeInfo(isolate, wrapper, wrapperTypeInfo, impl);
122 ASSERT(hasInternalFieldsSet(wrapper)); 116 ASSERT(hasInternalFieldsSet(wrapper));
123 } 117 }
124 SECURITY_CHECK(toScriptWrappable(wrapper) == impl); 118 SECURITY_CHECK(toScriptWrappable(wrapper) == impl);
125 return wrapper; 119 return wrapper;
126 } 120 }
127 121
128 inline v8::Local<v8::Object> V8DOMWrapper::associateObjectWithWrapper(
129 v8::Isolate* isolate,
130 Node* node,
131 const WrapperTypeInfo* wrapperTypeInfo,
132 v8::Local<v8::Object> wrapper) {
133 if (DOMDataStore::setWrapper(isolate, node, wrapperTypeInfo, wrapper)) {
134 wrapperTypeInfo->wrapperCreated();
135 setNativeInfo(isolate, wrapper, wrapperTypeInfo,
136 ScriptWrappable::fromNode(node));
137 ASSERT(hasInternalFieldsSet(wrapper));
138 }
139 SECURITY_CHECK(toScriptWrappable(wrapper) == ScriptWrappable::fromNode(node));
140 return wrapper;
141 }
142
143 class V8WrapperInstantiationScope { 122 class V8WrapperInstantiationScope {
144 STACK_ALLOCATED(); 123 STACK_ALLOCATED();
145 124
146 public: 125 public:
147 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext, 126 V8WrapperInstantiationScope(v8::Local<v8::Object> creationContext,
148 v8::Isolate* isolate, 127 v8::Isolate* isolate,
149 bool withSecurityCheck) 128 bool withSecurityCheck)
150 : m_didEnterContext(false), 129 : m_didEnterContext(false),
151 m_context(isolate->GetCurrentContext()), 130 m_context(isolate->GetCurrentContext()),
152 m_tryCatch(isolate), 131 m_tryCatch(isolate),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 175
197 bool m_didEnterContext; 176 bool m_didEnterContext;
198 v8::Local<v8::Context> m_context; 177 v8::Local<v8::Context> m_context;
199 v8::TryCatch m_tryCatch; 178 v8::TryCatch m_tryCatch;
200 bool m_convertExceptions; 179 bool m_convertExceptions;
201 }; 180 };
202 181
203 } // namespace blink 182 } // namespace blink
204 183
205 #endif // V8DOMWrapper_h 184 #endif // V8DOMWrapper_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/core/v8/V8Binding.h ('k') | third_party/WebKit/Source/core/dom/DocumentTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698