| OLD | NEW |
| 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 Loading... |
| 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 V8PerContextData* data = V8PerContextData::from(context); |
| 145 unsigned wanted; | 151 ASSERT(debugId); |
| 146 if (debugId == -1) | 152 data->m_originCategory = originCategory; |
| 147 wanted = snprintf(buffer, sizeof(buffer), "%s", worldName); | 153 data->m_contextCategory = contextCategory; |
| 148 else | 154 data->m_restrictions = restrictions; |
| 149 wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId); | 155 data->m_debugId = debugId; |
| 150 | |
| 151 if (wanted < sizeof(buffer)) | |
| 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 } | 156 } |
| 162 | 157 |
| 163 static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value>
value) | 158 void V8PerContextDebugData::setDebugDataForPage(v8::Handle<v8::Context> context,
int debugId) |
| 164 { | 159 { |
| 165 v8::Context::Scope contextScope(context); | 160 setDebugData( |
| 166 context->SetEmbedderData(v8ContextDebugIdIndex, value); | 161 context, |
| 162 CompilationOriginWeb, |
| 163 CompilationContextWebPage, |
| 164 CompilationRestrictionsNone, |
| 165 debugId |
| 166 ); |
| 167 } | 167 } |
| 168 | 168 |
| 169 bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context,
const char* worldName, int debugId) | 169 void V8PerContextDebugData::setDebugDataForContentScript(v8::Handle<v8::Context>
context, int debugId) |
| 170 { | 170 { |
| 171 if (!debugData(context)->IsUndefined()) | 171 setDebugData( |
| 172 return false; | 172 context, |
| 173 v8::HandleScope scope; | 173 CompilationOriginExtension, |
| 174 v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId); | 174 CompilationContextContentScript, |
| 175 setDebugData(context, debugData); | 175 CompilationRestrictionsNone, |
| 176 return true; | 176 debugId |
| 177 ); |
| 177 } | 178 } |
| 178 | 179 |
| 179 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context) | 180 void V8PerContextDebugData::setDebugDataForSystemUtility(v8::Handle<v8::Context>
context) |
| 181 { |
| 182 setDebugData( |
| 183 context, |
| 184 CompilationOriginSystem, |
| 185 CompilationContextUtility, |
| 186 CompilationRestrictionsNone, |
| 187 -1 |
| 188 ); |
| 189 } |
| 190 |
| 191 int V8PerContextDebugData::debugId(v8::Handle<v8::Context> context) |
| 192 { |
| 193 V8PerContextData* data = V8PerContextData::from(context); |
| 194 return data->m_debugId; |
| 195 } |
| 196 |
| 197 v8::Handle<v8::Value> V8PerContextDebugData::debugIdValue(v8::Handle<v8::Context
> context) |
| 198 { |
| 199 return v8::Integer::New(V8PerContextDebugData::debugId(context), context->Ge
tIsolate()); |
| 200 } |
| 201 |
| 202 CompilationOriginCategory V8PerContextDebugData::compilationOriginCategory(v8::H
andle<v8::Context> context) |
| 203 { |
| 204 V8PerContextData* data = V8PerContextData::from(context); |
| 205 return data->m_originCategory; |
| 206 } |
| 207 |
| 208 CompilationContextCategory V8PerContextDebugData::compilationContextCategory(v8:
:Handle<v8::Context> context) |
| 209 { |
| 210 V8PerContextData* data = V8PerContextData::from(context); |
| 211 return data->m_contextCategory; |
| 212 } |
| 213 |
| 214 v8::Handle<v8::Value> V8PerContextDebugData::compilationContextCategoryValue(v8:
:Handle<v8::Context> context) |
| 180 { | 215 { |
| 181 v8::HandleScope scope; | 216 v8::HandleScope scope; |
| 182 v8::Handle<v8::Value> data = debugData(context); | 217 CompilationContextCategory contextCategory = V8PerContextDebugData::compilat
ionContextCategory(context); |
| 218 v8::Handle<v8::Value> contextCategoryValue; |
| 219 switch(contextCategory) { |
| 220 case CompilationContextWebPage: |
| 221 contextCategoryValue = v8::String::NewSymbol("page"); |
| 222 break; |
| 223 case CompilationContextWorker: |
| 224 contextCategoryValue = v8::String::NewSymbol("worker"); |
| 225 break; |
| 226 case CompilationContextContentScript: |
| 227 contextCategoryValue = v8::String::NewSymbol("content-script"); |
| 228 break; |
| 229 default: |
| 230 contextCategoryValue = v8::Undefined(); |
| 231 break; |
| 232 } |
| 233 return scope.Close(contextCategoryValue); |
| 234 } |
| 183 | 235 |
| 184 if (!data->IsString()) | 236 CompilationRestrictions V8PerContextDebugData::compilationRestrictions(v8::Handl
e<v8::Context> context) |
| 185 return -1; | 237 { |
| 186 v8::String::AsciiValue ascii(data); | 238 V8PerContextData* data = V8PerContextData::from(context); |
| 187 char* comma = strnstr(*ascii, ",", ascii.length()); | 239 return data->m_restrictions; |
| 188 if (!comma) | 240 } |
| 189 return -1; | 241 |
| 190 return atoi(comma + 1); | 242 static CompilationOriginCategory commonOriginCategory[] = {CompilationOriginDevt
ools, CompilationOriginDevtools, CompilationOriginSystem}; |
| 243 static CompilationContextCategory commonContextCategory[] = {CompilationContextW
ebPage, CompilationContextWebPage, CompilationContextWebPage}; |
| 244 static CompilationRestrictions commonRestrictions[] = {CompilationRestrictionsNo
ne, CompilationRestrictionsOneFunction, CompilationRestrictionsNone}; |
| 245 |
| 246 V8ScopedCompilation::V8ScopedCompilation(v8::Handle<v8::Context> context, Scoped
CompilationCategory combo) |
| 247 : m_context(context) |
| 248 { |
| 249 init(commonOriginCategory[combo], commonContextCategory[combo], commonRestri
ctions[combo]); |
| 250 } |
| 251 |
| 252 V8ScopedCompilation::V8ScopedCompilation(v8::Handle<v8::Context> context, Compil
ationOriginCategory originCategory, CompilationContextCategory contextCategory,
CompilationRestrictions restrictions) |
| 253 : m_context(context) |
| 254 { |
| 255 init(originCategory, contextCategory, restrictions); |
| 256 } |
| 257 |
| 258 void V8ScopedCompilation::init(CompilationOriginCategory originCategory, Compila
tionContextCategory contextCategory, CompilationRestrictions restrictions) |
| 259 { |
| 260 V8PerContextData* data = V8PerContextData::from(m_context); |
| 261 m_originCategory = data->m_originCategory; |
| 262 m_contextCategory = data->m_contextCategory; |
| 263 m_restrictions = data->m_restrictions; |
| 264 m_debugId = data->m_debugId; |
| 265 V8PerContextDebugData::setDebugData(m_context, originCategory, contextCatego
ry, restrictions, m_debugId); |
| 266 } |
| 267 |
| 268 V8ScopedCompilation::~V8ScopedCompilation() |
| 269 { |
| 270 ASSERT(m_debugId); |
| 271 V8PerContextDebugData::setDebugData(m_context, m_originCategory, m_contextCa
tegory, m_restrictions, m_debugId); |
| 272 m_debugId = 0; |
| 191 } | 273 } |
| 192 | 274 |
| 193 } // namespace WebCore | 275 } // namespace WebCore |
| OLD | NEW |