1bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Copyright 2013 the V8 project authors. All rights reserved. 2bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Redistribution and use in source and binary forms, with or without 3bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// modification, are permitted provided that the following conditions are 4bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// met: 5bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// 6bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// * Redistributions of source code must retain the above copyright 7bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// notice, this list of conditions and the following disclaimer. 8bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// * Redistributions in binary form must reproduce the above 9bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// copyright notice, this list of conditions and the following 10bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// disclaimer in the documentation and/or other materials provided 11bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// with the distribution. 12bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// * Neither the name of Google Inc. nor the names of its 13bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// contributors may be used to endorse or promote products derived 14bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// from this software without specific prior written permission. 15bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// 16bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 28bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org#include "v8.h" 29bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org#include "arguments.h" 30bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 311510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org#include "vm-state-inl.h" 321510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org 33bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgnamespace v8 { 34bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgnamespace internal { 35bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 36bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 37bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgtemplate<typename T> 38bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgtemplate<typename V> 39bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgv8::Handle<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) { 40bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org // Check the ReturnValue. 41fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org Object** handle = &this->begin()[kReturnValueOffset]; 42bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org // Nothing was set, return empty handle as per previous behaviour. 43bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org if ((*handle)->IsTheHole()) return v8::Handle<V>(); 44f95d4b920abb640ab0986d138ad559a7d3b91d04danno@chromium.org return Utils::Convert<Object, V>(Handle<Object>(handle)); 45bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} 46bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 47bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 48662436e7b124b3535773535c671c53db322070b5verwaest@chromium.orgv8::Handle<v8::Value> FunctionCallbackArguments::Call(FunctionCallback f) { 49bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Isolate* isolate = this->isolate(); 501510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org VMState<EXTERNAL> state(isolate); 511510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); 52fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org FunctionCallbackInfo<v8::Value> info(begin(), 53662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org argv_, 54662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org argc_, 55662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org is_construct_call_); 56662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org f(info); 57bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org return GetReturnValue<v8::Value>(isolate); 58bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} 59bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 60bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 61662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org#define WRITE_CALL_0(Function, ReturnValue) \ 62662436e7b124b3535773535c671c53db322070b5verwaest@chromium.orgv8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f) { \ 63bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Isolate* isolate = this->isolate(); \ 641510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org VMState<EXTERNAL> state(isolate); \ 651510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 66fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org PropertyCallbackInfo<ReturnValue> info(begin()); \ 67662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org f(info); \ 68bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org return GetReturnValue<ReturnValue>(isolate); \ 69bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} 70bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 71662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org 72662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org#define WRITE_CALL_1(Function, ReturnValue, Arg1) \ 73662436e7b124b3535773535c671c53db322070b5verwaest@chromium.orgv8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \ 74bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Arg1 arg1) { \ 75bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Isolate* isolate = this->isolate(); \ 761510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org VMState<EXTERNAL> state(isolate); \ 771510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 78fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org PropertyCallbackInfo<ReturnValue> info(begin()); \ 79662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org f(arg1, info); \ 80bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org return GetReturnValue<ReturnValue>(isolate); \ 81bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} 82bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 83662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org 84662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org#define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2) \ 85662436e7b124b3535773535c671c53db322070b5verwaest@chromium.orgv8::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \ 86bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Arg1 arg1, \ 87bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Arg2 arg2) { \ 88bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Isolate* isolate = this->isolate(); \ 891510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org VMState<EXTERNAL> state(isolate); \ 901510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 91fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org PropertyCallbackInfo<ReturnValue> info(begin()); \ 92662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org f(arg1, arg2, info); \ 93bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org return GetReturnValue<ReturnValue>(isolate); \ 94bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} 95bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 96662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org 97662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org#define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \ 98662436e7b124b3535773535c671c53db322070b5verwaest@chromium.orgvoid PropertyCallbackArguments::Call(Function f, \ 99bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Arg1 arg1, \ 100bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Arg2 arg2) { \ 101bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org Isolate* isolate = this->isolate(); \ 1021510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org VMState<EXTERNAL> state(isolate); \ 1031510d58cbcf57c82a10e7d390bfe21a7ae68ba43mstarzinger@chromium.org ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \ 104fb7a7c4ffde9a4d060f5f989371e2ce964ee5831jkummerow@chromium.org PropertyCallbackInfo<ReturnValue> info(begin()); \ 105662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org f(arg1, arg2, info); \ 106bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} 107bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 108662436e7b124b3535773535c671c53db322070b5verwaest@chromium.org 109bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgFOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0) 110bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgFOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1) 111bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgFOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2) 112bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgFOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID) 113bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 114bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org#undef WRITE_CALL_0 115bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org#undef WRITE_CALL_1 116bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org#undef WRITE_CALL_2 117bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org#undef WRITE_CALL_2_VOID 118bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 119bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org 120f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.orgdouble ClobberDoubleRegisters(double x1, double x2, double x3, double x4) { 121f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org // TODO(ulan): This clobbers only subset of registers depending on compiler, 122f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org // Rewrite this in assembly to really clobber all registers. 123ecfa363c53ab5e5f01fb0645fabd2c060c967385ulan@chromium.org // GCC for ia32 uses the FPU and does not touch XMM registers. 124f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org return x1 * 1.01 + x2 * 2.02 + x3 * 3.03 + x4 * 4.04; 125f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org} 126f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org 127f9841897146bc10dbb3c45f0632bb79254602c75machenbach@chromium.org 128bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org} } // namespace v8::internal 129