Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Unified Diff: webkit/port/bindings/v8/V8NPUtils.cpp

Issue 155163: Downstream the partially upstreamed NPV8 files with fixes for errors introduced in upstreaming. (Closed)
Patch Set: hi Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/port/bindings/v8/V8NPUtils.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/port/bindings/v8/V8NPUtils.cpp
diff --git a/webkit/port/bindings/v8/V8NPUtils.cpp b/webkit/port/bindings/v8/V8NPUtils.cpp
index fa0d76f42c191e567975cdeefe21433b3f929266..e92db12f937d678dc892f88fde78c01978ed2c92 100644
--- a/webkit/port/bindings/v8/V8NPUtils.cpp
+++ b/webkit/port/bindings/v8/V8NPUtils.cpp
@@ -1,31 +1,32 @@
-// Copyright (c) 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/*
+ * Copyright (C) 2008, 2009 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
#include "config.h"
@@ -36,25 +37,24 @@
#include "PlatformString.h"
#undef LOG
-#include "npruntime_priv.h"
#include "NPV8Object.h"
#include "V8NPObject.h"
#include "V8Proxy.h"
+#include "npruntime_priv.h"
-void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject *owner, NPVariant* result)
+void convertV8ObjectToNPVariant(v8::Local<v8::Value> object, NPObject* owner, NPVariant* result)
{
VOID_TO_NPVARIANT(*result);
- // It is really the caller's responsibility to deal with the empty handle
- // case because there could be different actions to take in different
- // contexts.
+ // It is really the caller's responsibility to deal with the empty handle case because there could be different actions to
+ // take in different contexts.
ASSERT(!object.IsEmpty());
if (object.IsEmpty())
return;
if (object->IsInt32())
- INT32_TO_NPVARIANT(object->NumberValue(), *result);
+ INT32_TO_NPVARIANT(object->NumberValue(), *result);
else if (object->IsNumber())
DOUBLE_TO_NPVARIANT(object->NumberValue(), *result);
else if (object->IsBoolean())
@@ -81,42 +81,47 @@ v8::Handle<v8::Value> convertNPVariantToV8Object(const NPVariant* variant, NPObj
{
NPVariantType type = variant->type;
- if (type == NPVariantType_Int32)
+ switch (type) {
+ case NPVariantType_Int32:
return v8::Integer::New(NPVARIANT_TO_INT32(*variant));
- if (type == NPVariantType_Double)
+ case NPVariantType_Double:
return v8::Number::New(NPVARIANT_TO_DOUBLE(*variant));
- if (type == NPVariantType_Bool)
+ case NPVariantType_Bool:
return NPVARIANT_TO_BOOLEAN(*variant) ? v8::True() : v8::False();
- if (type == NPVariantType_Null)
+ case NPVariantType_Null:
return v8::Null();
- if (type == NPVariantType_Void)
+ case NPVariantType_Void:
return v8::Undefined();
- if (type == NPVariantType_String) {
+ case NPVariantType_String: {
NPString src = NPVARIANT_TO_STRING(*variant);
return v8::String::New(src.UTF8Characters, src.UTF8Length);
}
- if (type == NPVariantType_Object) {
+ case NPVariantType_Object: {
NPObject* obj = NPVARIANT_TO_OBJECT(*variant);
if (obj->_class == npScriptObjectClass)
return reinterpret_cast<V8NPObject*>(obj)->v8Object;
return createV8ObjectForNPObject(obj, npobject);
}
- return v8::Undefined();
+ default:
+ return v8::Undefined();
+ }
}
// Helper function to create an NPN String Identifier from a v8 string.
NPIdentifier getStringIdentifier(v8::Handle<v8::String> str)
{
- const int kStackBufSize = 100;
+ const int kStackBufferSize = 100;
- int bufLen = str->Length() + 1;
- if (bufLen <= kStackBufSize) {
- // Use local stack buffer to avoid heap allocations for small strings.
- // Here we should only use the stack space for stack_buf when it's used,
- // not when we use the heap.
- char stackBuf[kStackBufSize];
- str->WriteAscii(stackBuf);
- return NPN_GetStringIdentifier(stackBuf);
+ int bufferLength = str->Length() + 1;
+ if (bufferLength <= kStackBufferSize) {
+ // Use local stack buffer to avoid heap allocations for small strings. Here we should only use the stack space for
+ // stackBuffer when it's used, not when we use the heap.
+ //
+ // WriteAscii is guaranteed to generate a null-terminated string because bufferLength is constructed to be one greater
+ // than the string length.
+ char stackBuffer[kStackBufferSize];
+ str->WriteAscii(stackBuffer, 0, bufferLength);
+ return NPN_GetStringIdentifier(stackBuffer);
}
v8::String::AsciiValue ascii(str);
« no previous file with comments | « webkit/port/bindings/v8/V8NPUtils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698