| Index: Source/bindings/v8/V8PerContextData.cpp
|
| diff --git a/Source/bindings/v8/V8PerContextData.cpp b/Source/bindings/v8/V8PerContextData.cpp
|
| index 95c725f074099480cdbc0cc03221ae9d123b0a97..d8c93bf87f9a886e226e9e0014a09e5bcad8a5bc 100644
|
| --- a/Source/bindings/v8/V8PerContextData.cpp
|
| +++ b/Source/bindings/v8/V8PerContextData.cpp
|
| @@ -139,55 +139,137 @@ v8::Local<v8::Function> V8PerContextData::constructorForTypeSlowCase(WrapperType
|
|
|
| return function;
|
| }
|
| -static v8::Handle<v8::Value> createDebugData(const char* worldName, int debugId)
|
| +
|
| +void V8PerContextDebugData::setDebugData(
|
| + v8::Handle<v8::Context> context,
|
| + CompilationOriginCategory originCategory,
|
| + CompilationContextCategory contextCategory,
|
| + CompilationRestrictions restrictions,
|
| + int debugId)
|
| {
|
| - char buffer[32];
|
| - unsigned wanted;
|
| - if (debugId == -1)
|
| - wanted = snprintf(buffer, sizeof(buffer), "%s", worldName);
|
| - else
|
| - wanted = snprintf(buffer, sizeof(buffer), "%s,%d", worldName, debugId);
|
| + V8PerContextData* data = V8PerContextData::from(context);
|
| + ASSERT(debugId);
|
| + data->m_originCategory = originCategory;
|
| + data->m_contextCategory = contextCategory;
|
| + data->m_restrictions = restrictions;
|
| + data->m_debugId = debugId;
|
| +}
|
|
|
| - if (wanted < sizeof(buffer))
|
| - return v8::String::NewSymbol(buffer);
|
| +void V8PerContextDebugData::setDebugDataForPage(v8::Handle<v8::Context> context, int debugId)
|
| +{
|
| + setDebugData(
|
| + context,
|
| + CompilationOriginWeb,
|
| + CompilationContextWebPage,
|
| + CompilationRestrictionsNone,
|
| + debugId
|
| + );
|
| +}
|
|
|
| - return v8::Undefined();
|
| -};
|
| +void V8PerContextDebugData::setDebugDataForContentScript(v8::Handle<v8::Context> context, int debugId)
|
| +{
|
| + setDebugData(
|
| + context,
|
| + CompilationOriginExtension,
|
| + CompilationContextContentScript,
|
| + CompilationRestrictionsNone,
|
| + debugId
|
| + );
|
| +}
|
|
|
| -static v8::Handle<v8::Value> debugData(v8::Handle<v8::Context> context)
|
| +void V8PerContextDebugData::setDebugDataForSystemUtility(v8::Handle<v8::Context> context)
|
| {
|
| - v8::Context::Scope contextScope(context);
|
| - return context->GetEmbedderData(v8ContextDebugIdIndex);
|
| + setDebugData(
|
| + context,
|
| + CompilationOriginSystem,
|
| + CompilationContextUtility,
|
| + CompilationRestrictionsNone,
|
| + -1
|
| + );
|
| }
|
|
|
| -static void setDebugData(v8::Handle<v8::Context> context, v8::Handle<v8::Value> value)
|
| +int V8PerContextDebugData::debugId(v8::Handle<v8::Context> context)
|
| {
|
| - v8::Context::Scope contextScope(context);
|
| - context->SetEmbedderData(v8ContextDebugIdIndex, value);
|
| + V8PerContextData* data = V8PerContextData::from(context);
|
| + return data->m_debugId;
|
| }
|
|
|
| -bool V8PerContextDebugData::setContextDebugData(v8::Handle<v8::Context> context, const char* worldName, int debugId)
|
| +v8::Handle<v8::Value> V8PerContextDebugData::debugIdValue(v8::Handle<v8::Context> context)
|
| {
|
| - if (!debugData(context)->IsUndefined())
|
| - return false;
|
| - v8::HandleScope scope;
|
| - v8::Handle<v8::Value> debugData = createDebugData(worldName, debugId);
|
| - setDebugData(context, debugData);
|
| - return true;
|
| + return v8::Integer::New(V8PerContextDebugData::debugId(context), context->GetIsolate());
|
| +}
|
| +
|
| +CompilationOriginCategory V8PerContextDebugData::compilationOriginCategory(v8::Handle<v8::Context> context)
|
| +{
|
| + V8PerContextData* data = V8PerContextData::from(context);
|
| + return data->m_originCategory;
|
| }
|
|
|
| -int V8PerContextDebugData::contextDebugId(v8::Handle<v8::Context> context)
|
| +CompilationContextCategory V8PerContextDebugData::compilationContextCategory(v8::Handle<v8::Context> context)
|
| +{
|
| + V8PerContextData* data = V8PerContextData::from(context);
|
| + return data->m_contextCategory;
|
| +}
|
| +
|
| +v8::Handle<v8::Value> V8PerContextDebugData::compilationContextCategoryValue(v8::Handle<v8::Context> context)
|
| {
|
| v8::HandleScope scope;
|
| - v8::Handle<v8::Value> data = debugData(context);
|
| -
|
| - if (!data->IsString())
|
| - return -1;
|
| - v8::String::AsciiValue ascii(data);
|
| - char* comma = strnstr(*ascii, ",", ascii.length());
|
| - if (!comma)
|
| - return -1;
|
| - return atoi(comma + 1);
|
| + CompilationContextCategory contextCategory = V8PerContextDebugData::compilationContextCategory(context);
|
| + v8::Handle<v8::Value> contextCategoryValue;
|
| + switch(contextCategory) {
|
| + case CompilationContextWebPage:
|
| + contextCategoryValue = v8::String::NewSymbol("page");
|
| + break;
|
| + case CompilationContextWorker:
|
| + contextCategoryValue = v8::String::NewSymbol("worker");
|
| + break;
|
| + case CompilationContextContentScript:
|
| + contextCategoryValue = v8::String::NewSymbol("content-script");
|
| + break;
|
| + default:
|
| + contextCategoryValue = v8::Undefined();
|
| + break;
|
| + }
|
| + return scope.Close(contextCategoryValue);
|
| +}
|
| +
|
| +CompilationRestrictions V8PerContextDebugData::compilationRestrictions(v8::Handle<v8::Context> context)
|
| +{
|
| + V8PerContextData* data = V8PerContextData::from(context);
|
| + return data->m_restrictions;
|
| +}
|
| +
|
| +static CompilationOriginCategory commonOriginCategory[] = {CompilationOriginDevtools, CompilationOriginDevtools, CompilationOriginSystem};
|
| +static CompilationContextCategory commonContextCategory[] = {CompilationContextWebPage, CompilationContextWebPage, CompilationContextWebPage};
|
| +static CompilationRestrictions commonRestrictions[] = {CompilationRestrictionsNone, CompilationRestrictionsOneFunction, CompilationRestrictionsNone};
|
| +
|
| +V8ScopedCompilation::V8ScopedCompilation(v8::Handle<v8::Context> context, ScopedCompilationCategory combo)
|
| + : m_context(context)
|
| +{
|
| + init(commonOriginCategory[combo], commonContextCategory[combo], commonRestrictions[combo]);
|
| +}
|
| +
|
| +V8ScopedCompilation::V8ScopedCompilation(v8::Handle<v8::Context> context, CompilationOriginCategory originCategory, CompilationContextCategory contextCategory, CompilationRestrictions restrictions)
|
| + : m_context(context)
|
| +{
|
| + init(originCategory, contextCategory, restrictions);
|
| +}
|
| +
|
| +void V8ScopedCompilation::init(CompilationOriginCategory originCategory, CompilationContextCategory contextCategory, CompilationRestrictions restrictions)
|
| +{
|
| + V8PerContextData* data = V8PerContextData::from(m_context);
|
| + m_originCategory = data->m_originCategory;
|
| + m_contextCategory = data->m_contextCategory;
|
| + m_restrictions = data->m_restrictions;
|
| + m_debugId = data->m_debugId;
|
| + V8PerContextDebugData::setDebugData(m_context, originCategory, contextCategory, restrictions, m_debugId);
|
| +}
|
| +
|
| +V8ScopedCompilation::~V8ScopedCompilation()
|
| +{
|
| + ASSERT(m_debugId);
|
| + V8PerContextDebugData::setDebugData(m_context, m_originCategory, m_contextCategory, m_restrictions, m_debugId);
|
| + m_debugId = 0;
|
| }
|
|
|
| } // namespace WebCore
|
|
|