| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "bindings/core/v8/ScriptFunctionCall.h" | |
| 32 | |
| 33 #include "core/inspector/v8/V8DebuggerClient.h" | |
| 34 #include "wtf/PassOwnPtr.h" | |
| 35 | |
| 36 #include <v8.h> | |
| 37 | |
| 38 namespace blink { | |
| 39 | |
| 40 static v8::Local<v8::String> v8String(v8::Isolate* isolate, const String& string
) | |
| 41 { | |
| 42 v8::Local<v8::String> result; | |
| 43 bool success = v8::String::NewFromUtf8(isolate, string.utf8().data(), v8::Ne
wStringType::kNormal).ToLocal(&result); | |
| 44 ASSERT_UNUSED(success, success); | |
| 45 return result; | |
| 46 } | |
| 47 | |
| 48 ScriptFunctionCall::ScriptFunctionCall(V8DebuggerClient* client, v8::Local<v8::C
ontext> context, v8::Local<v8::Value> value, const String& name) | |
| 49 : m_client(client) | |
| 50 , m_context(context) | |
| 51 , m_name(v8String(context->GetIsolate(), name)) | |
| 52 , m_value(value) | |
| 53 { | |
| 54 } | |
| 55 | |
| 56 void ScriptFunctionCall::appendArgument(v8::Local<v8::Value> value) | |
| 57 { | |
| 58 m_arguments.append(value); | |
| 59 } | |
| 60 | |
| 61 void ScriptFunctionCall::appendArgument(const String& argument) | |
| 62 { | |
| 63 m_arguments.append(v8String(m_context->GetIsolate(), argument)); | |
| 64 } | |
| 65 | |
| 66 void ScriptFunctionCall::appendArgument(int argument) | |
| 67 { | |
| 68 m_arguments.append(v8::Number::New(m_context->GetIsolate(), argument)); | |
| 69 } | |
| 70 | |
| 71 void ScriptFunctionCall::appendArgument(bool argument) | |
| 72 { | |
| 73 m_arguments.append(argument ? v8::True(m_context->GetIsolate()) : v8::False(
m_context->GetIsolate())); | |
| 74 } | |
| 75 | |
| 76 void ScriptFunctionCall::appendUndefinedArgument() | |
| 77 { | |
| 78 m_arguments.append(v8::Undefined(m_context->GetIsolate())); | |
| 79 } | |
| 80 | |
| 81 v8::Local<v8::Value> ScriptFunctionCall::call(bool& hadException, bool reportExc
eptions) | |
| 82 { | |
| 83 v8::TryCatch tryCatch(m_context->GetIsolate()); | |
| 84 tryCatch.SetVerbose(reportExceptions); | |
| 85 | |
| 86 v8::Local<v8::Value> result = callWithoutExceptionHandling(); | |
| 87 hadException = tryCatch.HasCaught(); | |
| 88 return result; | |
| 89 } | |
| 90 | |
| 91 v8::Local<v8::Value> ScriptFunctionCall::call() | |
| 92 { | |
| 93 bool hadException = false; | |
| 94 return call(hadException); | |
| 95 } | |
| 96 | |
| 97 v8::Local<v8::Value> ScriptFunctionCall::callWithoutExceptionHandling() | |
| 98 { | |
| 99 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_value); | |
| 100 v8::Local<v8::Value> value; | |
| 101 if (!thisObject->Get(m_context, m_name).ToLocal(&value)) | |
| 102 return v8::Local<v8::Value>(); | |
| 103 | |
| 104 ASSERT(value->IsFunction()); | |
| 105 | |
| 106 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(value); | |
| 107 OwnPtr<v8::Local<v8::Value>[]> info = adoptArrayPtr(new v8::Local<v8::Value>
[m_arguments.size()]); | |
| 108 for (size_t i = 0; i < m_arguments.size(); ++i) { | |
| 109 info[i] = m_arguments[i]; | |
| 110 ASSERT(!info[i].IsEmpty()); | |
| 111 } | |
| 112 | |
| 113 v8::Local<v8::Value> result; | |
| 114 if (!m_client->callFunction(function, m_context, thisObject, m_arguments.siz
e(), info.get()).ToLocal(&result)) | |
| 115 return v8::Local<v8::Value>(); | |
| 116 return result; | |
| 117 } | |
| 118 | |
| 119 v8::Local<v8::Function> ScriptFunctionCall::function() | |
| 120 { | |
| 121 v8::TryCatch tryCatch(m_context->GetIsolate()); | |
| 122 v8::Local<v8::Object> thisObject = v8::Local<v8::Object>::Cast(m_value); | |
| 123 v8::Local<v8::Value> value; | |
| 124 if (!thisObject->Get(m_context, m_name).ToLocal(&value)) | |
| 125 return v8::Local<v8::Function>(); | |
| 126 | |
| 127 ASSERT(value->IsFunction()); | |
| 128 return v8::Local<v8::Function>::Cast(value); | |
| 129 } | |
| 130 | |
| 131 } // namespace blink | |
| OLD | NEW |