ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 1 | // 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.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 31 | #include "vm-state-inl.h" |
| 32 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
| 36 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 37 | template<typename T> |
| 38 | template<typename V> |
| 39 | v8::Handle<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) { |
| 40 | // Check the ReturnValue. |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 41 | Object** handle = &this->begin()[kReturnValueOffset]; |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 42 | // Nothing was set, return empty handle as per previous behaviour. |
| 43 | if ((*handle)->IsTheHole()) return v8::Handle<V>(); |
danno@chromium.org | f95d4b9 | 2013-06-13 14:40:17 +0000 | [diff] [blame] | 44 | return Utils::Convert<Object, V>(Handle<Object>(handle)); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 48 | v8::Handle<v8::Value> FunctionCallbackArguments::Call(FunctionCallback f) { |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 49 | Isolate* isolate = this->isolate(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 50 | VMState<EXTERNAL> state(isolate); |
| 51 | ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 52 | FunctionCallbackInfo<v8::Value> info(begin(), |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 53 | argv_, |
| 54 | argc_, |
| 55 | is_construct_call_); |
| 56 | f(info); |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 57 | return GetReturnValue<v8::Value>(isolate); |
| 58 | } |
| 59 | |
| 60 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 61 | #define WRITE_CALL_0(Function, ReturnValue) \ |
| 62 | v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f) { \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 63 | Isolate* isolate = this->isolate(); \ |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 64 | VMState<EXTERNAL> state(isolate); \ |
| 65 | ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 66 | PropertyCallbackInfo<ReturnValue> info(begin()); \ |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 67 | f(info); \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 68 | return GetReturnValue<ReturnValue>(isolate); \ |
| 69 | } |
| 70 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 71 | |
| 72 | #define WRITE_CALL_1(Function, ReturnValue, Arg1) \ |
| 73 | v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 74 | Arg1 arg1) { \ |
| 75 | Isolate* isolate = this->isolate(); \ |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 76 | VMState<EXTERNAL> state(isolate); \ |
| 77 | ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 78 | PropertyCallbackInfo<ReturnValue> info(begin()); \ |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 79 | f(arg1, info); \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 80 | return GetReturnValue<ReturnValue>(isolate); \ |
| 81 | } |
| 82 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 83 | |
| 84 | #define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2) \ |
| 85 | v8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 86 | Arg1 arg1, \ |
| 87 | Arg2 arg2) { \ |
| 88 | Isolate* isolate = this->isolate(); \ |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 89 | VMState<EXTERNAL> state(isolate); \ |
| 90 | ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 91 | PropertyCallbackInfo<ReturnValue> info(begin()); \ |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 92 | f(arg1, arg2, info); \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 93 | return GetReturnValue<ReturnValue>(isolate); \ |
| 94 | } |
| 95 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 96 | |
| 97 | #define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \ |
| 98 | void PropertyCallbackArguments::Call(Function f, \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 99 | Arg1 arg1, \ |
| 100 | Arg2 arg2) { \ |
| 101 | Isolate* isolate = this->isolate(); \ |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 102 | VMState<EXTERNAL> state(isolate); \ |
| 103 | ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 104 | PropertyCallbackInfo<ReturnValue> info(begin()); \ |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 105 | f(arg1, arg2, info); \ |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 106 | } |
| 107 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 108 | |
ulan@chromium.org | bf9432e | 2013-05-22 14:05:23 +0000 | [diff] [blame] | 109 | FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0) |
| 110 | FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1) |
| 111 | FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2) |
| 112 | FOR_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 |