Chromium Code Reviews| 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 String V8PerContextDebugData::contextCategory(v8::Handle<v8::Context> context) | |
| 198 { | |
| 199 v8::HandleScope scope; | |
| 200 v8::Handle<v8::Value> data = debugData(context); | |
| 201 | |
| 202 if (!data->IsString()) | |
| 203 return ""; | |
| 204 | |
| 205 v8::String::AsciiValue ascii(data); | |
| 206 char* comma = strnstr(*ascii, ",", ascii.length()); | |
| 207 if (!comma) | |
| 208 return ""; | |
| 209 | |
| 210 return String(*ascii, comma - *ascii); | |
| 211 } | |
| 212 | |
| 213 static V8PerContextDebugData::SystemScope* currentSystemScope = 0; | |
|
pfeldman
2013/05/01 07:33:55
static scope is likely to be non-workers friendly
| |
| 214 | |
| 215 bool V8PerContextDebugData::isSystemScope(v8::Handle<v8::Context> context) | |
|
pfeldman
2013/05/01 07:33:55
isSystemScope for Context does not correlate with
| |
| 216 { | |
| 217 if (currentSystemScope) { | |
| 218 return currentSystemScope->matches(context); | |
| 219 } else { | |
| 220 return false; | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 V8PerContextDebugData::SystemScope::SystemScope(v8::Handle<v8::Context> context) | |
| 225 : m_context(context) | |
| 226 { | |
| 227 currentSystemScope = this; | |
| 228 } | |
| 229 | |
| 230 V8PerContextDebugData::SystemScope::~SystemScope() | |
| 231 { | |
| 232 currentSystemScope = 0; | |
| 233 } | |
| 234 | |
| 235 bool V8PerContextDebugData::SystemScope::matches(v8::Handle<v8::Context> context ) | |
| 236 { | |
| 237 return context == m_context; | |
| 238 } | |
| 239 | |
| 193 } // namespace WebCore | 240 } // namespace WebCore |
| OLD | NEW |