blob: 3a4d733152ff8c7a0b0b7f059118541971852b1e [file] [log] [blame]
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +00001// Copyright 2013 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29#include "arguments.h"
30
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000031#include "vm-state-inl.h"
32
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000033namespace v8 {
34namespace internal {
35
36
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000037template<typename T>
38template<typename V>
39v8::Handle<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) {
40 // Check the ReturnValue.
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +000041 Object** handle = &this->begin()[kReturnValueOffset];
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000042 // Nothing was set, return empty handle as per previous behaviour.
43 if ((*handle)->IsTheHole()) return v8::Handle<V>();
danno@chromium.orgf95d4b92013-06-13 14:40:17 +000044 return Utils::Convert<Object, V>(Handle<Object>(handle));
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000045}
46
47
verwaest@chromium.org662436e2013-08-28 08:41:27 +000048v8::Handle<v8::Value> FunctionCallbackArguments::Call(FunctionCallback f) {
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000049 Isolate* isolate = this->isolate();
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000050 VMState<EXTERNAL> state(isolate);
51 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +000052 FunctionCallbackInfo<v8::Value> info(begin(),
verwaest@chromium.org662436e2013-08-28 08:41:27 +000053 argv_,
54 argc_,
55 is_construct_call_);
56 f(info);
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000057 return GetReturnValue<v8::Value>(isolate);
58}
59
60
verwaest@chromium.org662436e2013-08-28 08:41:27 +000061#define WRITE_CALL_0(Function, ReturnValue) \
62v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f) { \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000063 Isolate* isolate = this->isolate(); \
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000064 VMState<EXTERNAL> state(isolate); \
65 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +000066 PropertyCallbackInfo<ReturnValue> info(begin()); \
verwaest@chromium.org662436e2013-08-28 08:41:27 +000067 f(info); \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000068 return GetReturnValue<ReturnValue>(isolate); \
69}
70
verwaest@chromium.org662436e2013-08-28 08:41:27 +000071
72#define WRITE_CALL_1(Function, ReturnValue, Arg1) \
73v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000074 Arg1 arg1) { \
75 Isolate* isolate = this->isolate(); \
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000076 VMState<EXTERNAL> state(isolate); \
77 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +000078 PropertyCallbackInfo<ReturnValue> info(begin()); \
verwaest@chromium.org662436e2013-08-28 08:41:27 +000079 f(arg1, info); \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000080 return GetReturnValue<ReturnValue>(isolate); \
81}
82
verwaest@chromium.org662436e2013-08-28 08:41:27 +000083
84#define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2) \
85v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000086 Arg1 arg1, \
87 Arg2 arg2) { \
88 Isolate* isolate = this->isolate(); \
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +000089 VMState<EXTERNAL> state(isolate); \
90 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +000091 PropertyCallbackInfo<ReturnValue> info(begin()); \
verwaest@chromium.org662436e2013-08-28 08:41:27 +000092 f(arg1, arg2, info); \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000093 return GetReturnValue<ReturnValue>(isolate); \
94}
95
verwaest@chromium.org662436e2013-08-28 08:41:27 +000096
97#define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \
98void PropertyCallbackArguments::Call(Function f, \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +000099 Arg1 arg1, \
100 Arg2 arg2) { \
101 Isolate* isolate = this->isolate(); \
mstarzinger@chromium.org1510d582013-06-28 14:00:48 +0000102 VMState<EXTERNAL> state(isolate); \
103 ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
jkummerow@chromium.orgfb7a7c42013-10-02 11:41:02 +0000104 PropertyCallbackInfo<ReturnValue> info(begin()); \
verwaest@chromium.org662436e2013-08-28 08:41:27 +0000105 f(arg1, arg2, info); \
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000106}
107
verwaest@chromium.org662436e2013-08-28 08:41:27 +0000108
ulan@chromium.orgbf9432e2013-05-22 14:05:23 +0000109FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0)
110FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1)
111FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2)
112FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID)
113
114#undef WRITE_CALL_0
115#undef WRITE_CALL_1
116#undef WRITE_CALL_2
117#undef WRITE_CALL_2_VOID
118
119
120} } // namespace v8::internal