| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2008, 2009 Google Inc. All rights reserved. |    2  * Copyright (C) 2008, 2009 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   56  |   56  | 
|   57     if (object->IsNumber()) { |   57     if (object->IsNumber()) { | 
|   58         DOUBLE_TO_NPVARIANT(object->NumberValue(), *result); |   58         DOUBLE_TO_NPVARIANT(object->NumberValue(), *result); | 
|   59     } else if (object->IsBoolean()) { |   59     } else if (object->IsBoolean()) { | 
|   60         BOOLEAN_TO_NPVARIANT(object->BooleanValue(), *result); |   60         BOOLEAN_TO_NPVARIANT(object->BooleanValue(), *result); | 
|   61     } else if (object->IsNull()) { |   61     } else if (object->IsNull()) { | 
|   62         NULL_TO_NPVARIANT(*result); |   62         NULL_TO_NPVARIANT(*result); | 
|   63     } else if (object->IsUndefined()) { |   63     } else if (object->IsUndefined()) { | 
|   64         VOID_TO_NPVARIANT(*result); |   64         VOID_TO_NPVARIANT(*result); | 
|   65     } else if (object->IsString()) { |   65     } else if (object->IsString()) { | 
|   66         v8::Handle<v8::String> str = object.As<v8::String>(); |   66         v8::Local<v8::String> str = object.As<v8::String>(); | 
|   67         int length = str->Utf8Length() + 1; |   67         int length = str->Utf8Length() + 1; | 
|   68         char* utf8Chars = reinterpret_cast<char*>(malloc(length)); |   68         char* utf8Chars = reinterpret_cast<char*>(malloc(length)); | 
|   69         str->WriteUtf8(utf8Chars, length, 0, v8::String::HINT_MANY_WRITES_EXPECT
     ED); |   69         str->WriteUtf8(utf8Chars, length, 0, v8::String::HINT_MANY_WRITES_EXPECT
     ED); | 
|   70         STRINGN_TO_NPVARIANT(utf8Chars, length-1, *result); |   70         STRINGN_TO_NPVARIANT(utf8Chars, length-1, *result); | 
|   71     } else if (object->IsObject()) { |   71     } else if (object->IsObject()) { | 
|   72         LocalDOMWindow* window = currentDOMWindow(isolate); |   72         LocalDOMWindow* window = currentDOMWindow(isolate); | 
|   73         NPObject* npobject = npCreateV8ScriptObject(isolate, 0, v8::Handle<v8::O
     bject>::Cast(object), window); |   73         NPObject* npobject = npCreateV8ScriptObject(isolate, 0, v8::Local<v8::Ob
     ject>::Cast(object), window); | 
|   74         if (npobject) |   74         if (npobject) | 
|   75             _NPN_RegisterObject(npobject, owner); |   75             _NPN_RegisterObject(npobject, owner); | 
|   76         OBJECT_TO_NPVARIANT(npobject, *result); |   76         OBJECT_TO_NPVARIANT(npobject, *result); | 
|   77     } |   77     } | 
|   78 } |   78 } | 
|   79  |   79  | 
|   80 v8::Handle<v8::Value> convertNPVariantToV8Object(v8::Isolate* isolate, const NPV
     ariant* variant, NPObject* owner) |   80 v8::Local<v8::Value> convertNPVariantToV8Object(v8::Isolate* isolate, const NPVa
     riant* variant, NPObject* owner) | 
|   81 { |   81 { | 
|   82     NPVariantType type = variant->type; |   82     NPVariantType type = variant->type; | 
|   83  |   83  | 
|   84     switch (type) { |   84     switch (type) { | 
|   85     case NPVariantType_Int32: |   85     case NPVariantType_Int32: | 
|   86         return v8::Integer::New(isolate, NPVARIANT_TO_INT32(*variant)); |   86         return v8::Integer::New(isolate, NPVARIANT_TO_INT32(*variant)); | 
|   87     case NPVariantType_Double: |   87     case NPVariantType_Double: | 
|   88         return v8::Number::New(isolate, NPVARIANT_TO_DOUBLE(*variant)); |   88         return v8::Number::New(isolate, NPVARIANT_TO_DOUBLE(*variant)); | 
|   89     case NPVariantType_Bool: |   89     case NPVariantType_Bool: | 
|   90         return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant), isolate); |   90         return v8Boolean(NPVARIANT_TO_BOOLEAN(*variant), isolate); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  101         if (V8NPObject* v8Object = npObjectToV8NPObject(object)) |  101         if (V8NPObject* v8Object = npObjectToV8NPObject(object)) | 
|  102             return v8::Local<v8::Object>::New(isolate, v8Object->v8Object); |  102             return v8::Local<v8::Object>::New(isolate, v8Object->v8Object); | 
|  103         return createV8ObjectForNPObject(isolate, object, owner); |  103         return createV8ObjectForNPObject(isolate, object, owner); | 
|  104     } |  104     } | 
|  105     default: |  105     default: | 
|  106         return v8::Undefined(isolate); |  106         return v8::Undefined(isolate); | 
|  107     } |  107     } | 
|  108 } |  108 } | 
|  109  |  109  | 
|  110 // Helper function to create an NPN String Identifier from a v8 string. |  110 // Helper function to create an NPN String Identifier from a v8 string. | 
|  111 NPIdentifier getStringIdentifier(v8::Handle<v8::String> str) |  111 NPIdentifier getStringIdentifier(v8::Local<v8::String> str) | 
|  112 { |  112 { | 
|  113     const int kStackBufferSize = 100; |  113     const int kStackBufferSize = 100; | 
|  114  |  114  | 
|  115     int bufferLength = str->Utf8Length() + 1; |  115     int bufferLength = str->Utf8Length() + 1; | 
|  116     if (bufferLength <= kStackBufferSize) { |  116     if (bufferLength <= kStackBufferSize) { | 
|  117         // Use local stack buffer to avoid heap allocations for small strings. H
     ere we should only use the stack space for |  117         // Use local stack buffer to avoid heap allocations for small strings. H
     ere we should only use the stack space for | 
|  118         // stackBuffer when it's used, not when we use the heap. |  118         // stackBuffer when it's used, not when we use the heap. | 
|  119         // |  119         // | 
|  120         // WriteUtf8 is guaranteed to generate a null-terminated string because 
     bufferLength is constructed to be one greater |  120         // WriteUtf8 is guaranteed to generate a null-terminated string because 
     bufferLength is constructed to be one greater | 
|  121         // than the string length. |  121         // than the string length. | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  162 ExceptionCatcher::~ExceptionCatcher() |  162 ExceptionCatcher::~ExceptionCatcher() | 
|  163 { |  163 { | 
|  164     if (!m_tryCatch.HasCaught()) |  164     if (!m_tryCatch.HasCaught()) | 
|  165         return; |  165         return; | 
|  166  |  166  | 
|  167     if (topHandler) |  167     if (topHandler) | 
|  168         topHandler->handler(topHandler->data, *v8::String::Utf8Value(m_tryCatch.
     Exception())); |  168         topHandler->handler(topHandler->data, *v8::String::Utf8Value(m_tryCatch.
     Exception())); | 
|  169 } |  169 } | 
|  170  |  170  | 
|  171 } // namespace blink |  171 } // namespace blink | 
| OLD | NEW |