| 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 |
| 142 static v8::Handle<v8::Value> createDebugData(const char* worldName, int debugId)
| 143 static v8::Handle<v8::Value> createDebugData(const char* worldName, int debugId)
|
| 143 { | 144 { |
| 144 char buffer[32]; | 145 char buffer[32]; |
| 145 unsigned wanted; | 146 unsigned wanted; |
| 146 if (debugId == -1) | 147 if (debugId == -1) |
| 147 wanted = snprintf(buffer, sizeof(buffer), "%s", worldName); | 148 wanted = snprintf(buffer, sizeof(buffer), "%s", worldName); |
| 148 else | 149 else |
| 149 wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId); | 150 wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId); |
| 150 | 151 |
| 151 if (wanted < sizeof(buffer)) | 152 if (wanted < sizeof(buffer)) |
| 152 return v8::String::NewSymbol(buffer); | 153 return v8::String::NewSymbol(buffer); |
| 153 | 154 |
| 154 return v8::Undefined(); | 155 return v8::Undefined(); |
| 155 }; | 156 }; |
| 156 | 157 |
| 157 static v8::Handle<v8::Value> debugData(v8::Handle<v8::Context> context) | 158 static v8::Handle<v8::Value> debugData(v8::Handle<v8::Context> context) |
| 158 { | 159 { |
| 159 v8::Context::Scope contextScope(context); | 160 v8::Context::Scope contextScope(context); |
| 160 return context->GetEmbedderData(v8ContextDebugIdIndex); | 161 return context->GetEmbedderData(v8ContextDebugIdIndex); |
| 161 } | 162 } |
| 162 | 163 |
| 163 static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value>
value) | 164 static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value>
value) |
| 164 { | 165 { |
| 165 v8::Context::Scope contextScope(context); | 166 ASSERT(*value); |
| 167 ASSERT(value->IsString()); |
| 166 context->SetEmbedderData(v8ContextDebugIdIndex, value); | 168 context->SetEmbedderData(v8ContextDebugIdIndex, value); |
| 167 } | 169 } |
| 168 | 170 |
| 169 bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context,
const char* worldName, int debugId) | 171 bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context,
const char* worldName, int debugId) |
| 170 { | 172 { |
| 173 v8::HandleScope scope; |
| 171 if (!debugData(context)->IsUndefined()) | 174 if (!debugData(context)->IsUndefined()) |
| 172 return false; | 175 return false; |
| 173 v8::HandleScope scope; | 176 ASSERT(debugId); |
| 177 v8::Context::Scope contextScope(context); |
| 174 v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId); | 178 v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId); |
| 175 setDebugData(context, debugData); | 179 setDebugData(context, debugData); |
| 176 return true; | 180 return true; |
| 177 } | 181 } |
| 178 | 182 |
| 179 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context) | 183 int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context) |
| 180 { | 184 { |
| 181 v8::HandleScope scope; | 185 v8::HandleScope scope; |
| 182 v8::Handle<v8::Value> data = debugData(context); | 186 v8::Handle<v8::Value> data = debugData(context); |
| 183 | 187 |
| 184 if (!data->IsString()) | 188 if (!data->IsString()) |
| 185 return -1; | 189 return -1; |
| 186 v8::String::AsciiValue ascii(data); | 190 v8::String::AsciiValue ascii(data); |
| 187 char* comma = strnstr(*ascii, ",", ascii.length()); | 191 char* comma = strnstr(*ascii, ",", ascii.length()); |
| 188 if (!comma) | 192 if (!comma) |
| 189 return -1; | 193 return -1; |
| 190 return atoi(comma + 1); | 194 return atoi(comma + 1); |
| 191 } | 195 } |
| 192 | 196 |
| 197 ContextCategory V8PerContextDebugData::contextCategory(v8::Handle<v8::Context> c
ontext) |
| 198 { |
| 199 v8::HandleScope scope; |
| 200 v8::Handle<v8::Value> data = debugData(context); |
| 201 |
| 202 if (!data->IsString()) |
| 203 return NoContextCategory; |
| 204 |
| 205 v8::String::AsciiValue ascii(data); |
| 206 char* comma = strnstr(*ascii, ",", ascii.length()); |
| 207 if (!comma) |
| 208 return NoContextCategory; |
| 209 |
| 210 String categoryString(*ascii, comma - *ascii); |
| 211 if (categoryString == "page") { |
| 212 return PageContextCategory; |
| 213 } |
| 214 if (categoryString == "worker") { |
| 215 return WorkerContextCategory; |
| 216 } |
| 217 if (categoryString == "injected") { |
| 218 return ContentScriptContextCategory; |
| 219 } |
| 220 return NoContextCategory; |
| 221 } |
| 222 |
| 223 static V8PerContextDebugData::ScopedWebCompilation* currentScopedWebCompilation
= 0; |
| 224 static bool matches(v8::Handle<v8::Context> l_context, v8::Handle<v8::Context> r
_context) |
| 225 { |
| 226 return l_context == r_context; |
| 227 } |
| 228 |
| 229 bool V8PerContextDebugData::isScopedWebCompilation(v8::Handle<v8::Context> conte
xt) |
| 230 { |
| 231 if (currentScopedWebCompilation) { |
| 232 return matches(currentScopedWebCompilation->m_context, context); |
| 233 } else { |
| 234 return false; |
| 235 } |
| 236 } |
| 237 |
| 238 bool V8PerContextDebugData::isOneFunctionWebCompilation() |
| 239 { |
| 240 if (currentScopedWebCompilation) { |
| 241 return currentScopedWebCompilation->m_oneFunctionResult; |
| 242 } else { |
| 243 return false; |
| 244 } |
| 245 } |
| 246 |
| 247 V8PerContextDebugData::ScopedWebCompilation::ScopedWebCompilation(v8::Handle<v8:
:Context> context, bool oneFunctionResult) |
| 248 : m_context(context), m_oneFunctionResult(oneFunctionResult) |
| 249 { |
| 250 // In some cases we may over-write a value other than zero because we eg com
pile - run - compile all on the same |
| 251 // call stack. This is ok: we only need the pointer before each compile and
before we ever run the code. |
| 252 currentScopedWebCompilation = this; |
| 253 } |
| 254 |
| 255 V8PerContextDebugData::ScopedWebCompilation::~ScopedWebCompilation() |
| 256 { |
| 257 currentScopedWebCompilation = 0; |
| 258 } |
| 259 |
| 260 |
| 193 } // namespace WebCore | 261 } // namespace WebCore |
| OLD | NEW |