From 1aaa57c5e862385a79307bfa3ba5e6910bd42a0d Mon Sep 17 00:00:00 2001 From: "eric@webkit.org" Date: Thu, 26 Nov 2009 08:43:41 +0000 Subject: [PATCH] =?utf8?q?2009-11-26=20=20S=C3=B8ren=20Gjesse=20=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed by Pavel Feldman. [V8] Avoid using JavaScript objects as context data https://bugs.webkit.org/show_bug.cgi?id=31873 Change the context "data" from a JavaScript object holding the two properties type and value to a string holding type and value separated by a comma. * bindings/v8/V8Proxy.cpp: (WebCore::V8Proxy::setInjectedScriptContextDebugId): (WebCore::V8Proxy::setContextDebugId): (WebCore::V8Proxy::contextDebugId): git-svn-id: https://svn.webkit.org/repository/webkit/trunk@51407 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 15 ++++++++++++ WebCore/bindings/v8/V8Proxy.cpp | 43 ++++++++++++++------------------- WebCore/bindings/v8/V8Proxy.h | 3 --- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 7d79ea6c6127..e314ac138785 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,18 @@ +2009-11-26 Søren Gjesse + + Reviewed by Pavel Feldman. + + [V8] Avoid using JavaScript objects as context data + https://bugs.webkit.org/show_bug.cgi?id=31873 + + Change the context "data" from a JavaScript object holding the two properties type and value to + a string holding type and value separated by a comma. + + * bindings/v8/V8Proxy.cpp: + (WebCore::V8Proxy::setInjectedScriptContextDebugId): + (WebCore::V8Proxy::setContextDebugId): + (WebCore::V8Proxy::contextDebugId): + 2009-11-25 Dimitri Glazkov Reviewed by David Levin. diff --git a/WebCore/bindings/v8/V8Proxy.cpp b/WebCore/bindings/v8/V8Proxy.cpp index 89a8b57f0705..6764d0d77795 100644 --- a/WebCore/bindings/v8/V8Proxy.cpp +++ b/WebCore/bindings/v8/V8Proxy.cpp @@ -54,12 +54,14 @@ #include "WorkerContextExecutionProxy.h" #include +#include #include #include #include #include #include #include +#include #include namespace WebCore { @@ -69,9 +71,6 @@ v8::Persistent V8Proxy::m_utilityContext; // Static list of registered extensions V8Extensions V8Proxy::m_extensions; -const char* V8Proxy::kContextDebugDataType = "type"; -const char* V8Proxy::kContextDebugDataValue = "value"; - void batchConfigureAttributes(v8::Handle instance, v8::Handle proto, const BatchedAttribute* attributes, @@ -387,24 +386,16 @@ bool V8Proxy::setInjectedScriptContextDebugId(v8::Handle targetCont { // Setup context id for JS debugger. v8::Context::Scope contextScope(targetContext); - v8::Handle contextData = v8::Object::New(); - if (contextData.IsEmpty()) - return false; - if (m_context.IsEmpty()) return false; - v8::Handle windowContextData = m_context->GetData(); - if (windowContextData->IsObject()) { - v8::Handle propertyName = v8::String::New(kContextDebugDataValue); - if (propertyName.IsEmpty()) - return false; - contextData->Set(propertyName, v8::Object::Cast(*windowContextData)->Get(propertyName)); - } - v8::Handle propertyName = v8::String::New(kContextDebugDataType); - if (propertyName.IsEmpty()) + int debugId = contextDebugId(m_context); + if (debugId == -1) return false; - contextData->Set(propertyName, v8::String::New("injected")); - targetContext->SetData(contextData); + + char buffer[32]; + snprintf(buffer, sizeof(buffer), "injected,%d", debugId); + targetContext->SetData(v8::String::New(buffer)); + return true; } @@ -1366,20 +1357,22 @@ bool V8Proxy::setContextDebugId(int debugId) return false; v8::Context::Scope contextScope(m_context); - v8::Handle contextData = v8::Object::New(); - contextData->Set(v8::String::New(kContextDebugDataType), v8::String::New("page")); - contextData->Set(v8::String::New(kContextDebugDataValue), v8::Integer::New(debugId)); - m_context->SetData(contextData); + + char buffer[32]; + snprintf(buffer, sizeof(buffer), "page,%d", debugId); + m_context->SetData(v8::String::New(buffer)); + return true; } int V8Proxy::contextDebugId(v8::Handle context) { v8::HandleScope scope; - if (!context->GetData()->IsObject()) + if (!context->GetData()->IsString()) return -1; - v8::Handle data = context->GetData()->ToObject()->Get( v8::String::New(kContextDebugDataValue)); - return data->IsInt32() ? data->Int32Value() : -1; + v8::String::AsciiValue ascii(context->GetData()); + char* comma = strnstr(*ascii, ",", ascii.length()); + return atoi(comma + 1); } v8::Handle V8Proxy::getHiddenObjectPrototype(v8::Handle context) diff --git a/WebCore/bindings/v8/V8Proxy.h b/WebCore/bindings/v8/V8Proxy.h index c8628d105e9d..ab351af35d0c 100644 --- a/WebCore/bindings/v8/V8Proxy.h +++ b/WebCore/bindings/v8/V8Proxy.h @@ -365,9 +365,6 @@ namespace WebCore { void updateDocumentWrapper(v8::Handle wrapper); private: - static const char* kContextDebugDataType; - static const char* kContextDebugDataValue; - void setSecurityToken(); void clearDocumentWrapper(); -- 2.36.0