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

Side by Side Diff: Source/bindings/v8/V8PerContextData.cpp

Issue 14362015: WIP enum / V8PerContextData solution (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « Source/bindings/v8/V8PerContextData.h ('k') | Source/bindings/v8/V8PerContextDebugData.h » ('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) 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd ex, type); 132 prototypeObject->SetAlignedPointerInInternalField(v8PrototypeTypeInd ex, type);
133 type->installPerContextPrototypeProperties(prototypeObject, m_context->G etIsolate()); 133 type->installPerContextPrototypeProperties(prototypeObject, m_context->G etIsolate());
134 if (type->wrapperTypePrototype == WrapperTypeErrorPrototype) 134 if (type->wrapperTypePrototype == WrapperTypeErrorPrototype)
135 prototypeObject->SetPrototype(m_errorPrototype.get()); 135 prototypeObject->SetPrototype(m_errorPrototype.get());
136 } 136 }
137 137
138 m_constructorMap.set(type, v8::Persistent<v8::Function>::New(m_context->GetI solate(), function)); 138 m_constructorMap.set(type, v8::Persistent<v8::Function>::New(m_context->GetI solate(), function));
139 139
140 return function; 140 return function;
141 } 141 }
142 static v8::Handle<v8::Value> createDebugData(const char* worldName, int debugId) 142
143 void V8PerContextDebugData::setDebugData(
144 v8::Handle<v8::Context> context,
145 CompilationOriginCategory originCategory,
146 CompilationContextCategory contextCategory,
147 CompilationRestrictions restrictions,
148 int debugId)
143 { 149 {
144 char buffer[32]; 150 v8::HandleScope scope;
145 unsigned wanted; 151 V8PerContextData* data = V8PerContextData::from(context);
146 if (debugId == -1) 152 ASSERT(debugId);
147 wanted = snprintf(buffer, sizeof(buffer), "%s", worldName); 153
148 else 154 data->m_originCategory = originCategory;
149 wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId); 155 data->m_contextCategory = contextCategory;
150 156 data->m_restrictions = restrictions;
151 if (wanted < sizeof(buffer)) 157 data->m_debugId = debugId;
152 return v8::String::NewSymbol(buffer);
153
154 return v8::Undefined();
155 };
156
157 static v8::Handle<v8::Value> debugData(v8::Handle<v8::Context> context)
158 {
159 v8::Context::Scope contextScope(context);
160 return context->GetEmbedderData(v8ContextDebugIdIndex);
161 } 158 }
162 159
163 static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value> value) 160 void V8PerContextDebugData::setDebugDataForPage(v8::Handle<v8::Context> context, int debugId)
164 { 161 {
165 v8::Context::Scope contextScope(context); 162 setDebugData(
166 context->SetEmbedderData(v8ContextDebugIdIndex, value); 163 context,
164 CompilationOriginWeb,
165 CompilationContextWebPage,
166 CompilationRestrictionsNone,
167 debugId
168 );
167 } 169 }
168 170
169 bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context, const char* worldName, int debugId) 171 void V8PerContextDebugData::setDebugDataForContentScript(v8::Handle<v8::Context> context, int debugId)
170 { 172 {
171 if (!debugData(context)->IsUndefined()) 173 setDebugData(
172 return false; 174 context,
173 v8::HandleScope scope; 175 CompilationOriginExtension,
174 v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId); 176 CompilationContextContentScript,
175 setDebugData(context, debugData); 177 CompilationRestrictionsNone,
176 return true; 178 debugId
179 );
177 } 180 }
178 181
179 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context) 182 void V8PerContextDebugData::setDebugDataForSystemUtility(v8::Handle<v8::Context> context)
183 {
184 setDebugData(
185 context,
186 CompilationOriginSystem,
187 CompilationContextUtility,
188 CompilationRestrictionsNone,
189 -1
190 );
191 }
192
193 int V8PerContextDebugData::debugId(v8::Handle<v8::Context> context)
180 { 194 {
181 v8::HandleScope scope; 195 v8::HandleScope scope;
182 v8::Handle<v8::Value> data = debugData(context); 196 V8PerContextData* data = V8PerContextData::from(context);
197 return data->m_debugId;
198 }
183 199
184 if (!data->IsString()) 200 CompilationOriginCategory V8PerContextDebugData::compilationOriginCategory(v8::H andle<v8::Context> context)
185 return -1; 201 {
186 v8::String::AsciiValue ascii(data); 202 v8::HandleScope scope;
187 char* comma = strnstr(*ascii, ",", ascii.length()); 203 V8PerContextData* data = V8PerContextData::from(context);
188 if (!comma) 204 return data->m_originCategory;
189 return -1; 205 }
190 return atoi(comma + 1); 206
207 CompilationContextCategory V8PerContextDebugData::compilationContextCategory(v8: :Handle<v8::Context> context)
208 {
209 v8::HandleScope scope;
210 V8PerContextData* data = V8PerContextData::from(context);
211 return data->m_contextCategory;
212 }
213
214 CompilationRestrictions V8PerContextDebugData::compilationRestrictions(v8::Handl e<v8::Context> context)
215 {
216 v8::HandleScope scope;
217 V8PerContextData* data = V8PerContextData::from(context);
218 return data->m_restrictions;
219 }
220
221 static CompilationOriginCategory commonOriginCategory[] = {CompilationOriginDevt ools, CompilationOriginDevtools, CompilationOriginSystem};
222 static CompilationContextCategory commonContextCategory[] = {CompilationContextW ebPage, CompilationContextWebPage, CompilationContextWebPage};
223 static CompilationRestrictions commonRestrictions[] = {CompilationRestrictionsNo ne, CompilationRestrictionsOneFunction, CompilationRestrictionsNone};
224
225 V8ScopedCompilation::V8ScopedCompilation(v8::Handle<v8::Context> context, Scoped CompilationCategory combo)
226 : m_context(context)
227 {
228 init(commonOriginCategory[combo], commonContextCategory[combo], commonRestri ctions[combo]);
229 }
230
231 V8ScopedCompilation::V8ScopedCompilation(v8::Handle<v8::Context> context, Compil ationOriginCategory originCategory, CompilationContextCategory contextCategory, CompilationRestrictions restrictions)
232 : m_context(context)
233 {
234 init(originCategory, contextCategory, restrictions);
235 }
236
237 void V8ScopedCompilation::init(CompilationOriginCategory originCategory, Compila tionContextCategory contextCategory, CompilationRestrictions restrictions)
238 {
239 V8PerContextData* data = V8PerContextData::from(m_context);
240 m_originCategory = data->m_originCategory;
241 m_contextCategory = data->m_contextCategory;
242 m_restrictions = data->m_restrictions;
243 m_debugId = data->m_debugId;
244 V8PerContextDebugData::setDebugData(m_context, originCategory, contextCatego ry, restrictions, m_debugId);
245 }
246
247 V8ScopedCompilation::~V8ScopedCompilation()
248 {
249 ASSERT(!m_debugId);
250 v8::HandleScope scope;
251 V8PerContextDebugData::setDebugData(m_context, m_originCategory, m_contextCa tegory, m_restrictions, m_debugId);
252 m_debugId = 0;
191 } 253 }
192 254
193 } // namespace WebCore 255 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/V8PerContextData.h ('k') | Source/bindings/v8/V8PerContextDebugData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698