• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/arguments.h"
6 
7 #include "src/api.h"
8 #include "src/vm-state-inl.h"
9 
10 namespace v8 {
11 namespace internal {
12 
13 
14 template <typename T>
15 template <typename V>
GetReturnValue(Isolate * isolate)16 v8::Local<V> CustomArguments<T>::GetReturnValue(Isolate* isolate) {
17   // Check the ReturnValue.
18   Object** handle = &this->begin()[kReturnValueOffset];
19   // Nothing was set, return empty handle as per previous behaviour.
20   if ((*handle)->IsTheHole()) return v8::Local<V>();
21   return Utils::Convert<Object, V>(Handle<Object>(handle));
22 }
23 
24 
Call(FunctionCallback f)25 v8::Local<v8::Value> FunctionCallbackArguments::Call(FunctionCallback f) {
26   Isolate* isolate = this->isolate();
27   VMState<EXTERNAL> state(isolate);
28   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
29   FunctionCallbackInfo<v8::Value> info(begin(),
30                                        argv_,
31                                        argc_,
32                                        is_construct_call_);
33   f(info);
34   return GetReturnValue<v8::Value>(isolate);
35 }
36 
37 
38 #define WRITE_CALL_0(Function, ReturnValue)                            \
39   v8::Local<ReturnValue> PropertyCallbackArguments::Call(Function f) { \
40     Isolate* isolate = this->isolate();                                \
41     VMState<EXTERNAL> state(isolate);                                  \
42     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));       \
43     PropertyCallbackInfo<ReturnValue> info(begin());                   \
44     f(info);                                                           \
45     return GetReturnValue<ReturnValue>(isolate);                       \
46   }
47 
48 
49 #define WRITE_CALL_1(Function, ReturnValue, Arg1)                     \
50   v8::Local<ReturnValue> PropertyCallbackArguments::Call(Function f,  \
51                                                          Arg1 arg1) { \
52     Isolate* isolate = this->isolate();                               \
53     VMState<EXTERNAL> state(isolate);                                 \
54     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));      \
55     PropertyCallbackInfo<ReturnValue> info(begin());                  \
56     f(arg1, info);                                                    \
57     return GetReturnValue<ReturnValue>(isolate);                      \
58   }
59 
60 
61 #define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2)          \
62   v8::Local<ReturnValue> PropertyCallbackArguments::Call(        \
63       Function f, Arg1 arg1, Arg2 arg2) {                        \
64     Isolate* isolate = this->isolate();                          \
65     VMState<EXTERNAL> state(isolate);                            \
66     ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
67     PropertyCallbackInfo<ReturnValue> info(begin());             \
68     f(arg1, arg2, info);                                         \
69     return GetReturnValue<ReturnValue>(isolate);                 \
70   }
71 
72 
73 #define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2)                   \
74 void PropertyCallbackArguments::Call(Function f,                               \
75                                      Arg1 arg1,                                \
76                                      Arg2 arg2) {                              \
77   Isolate* isolate = this->isolate();                                          \
78   VMState<EXTERNAL> state(isolate);                                            \
79   ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));                 \
80   PropertyCallbackInfo<ReturnValue> info(begin());                             \
81   f(arg1, arg2, info);                                                         \
82 }
83 
84 
85 FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0)
FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1)86 FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1)
87 FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2)
88 FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID)
89 
90 #undef WRITE_CALL_0
91 #undef WRITE_CALL_1
92 #undef WRITE_CALL_2
93 #undef WRITE_CALL_2_VOID
94 
95 
96 double ClobberDoubleRegisters(double x1, double x2, double x3, double x4) {
97   // TODO(ulan): This clobbers only subset of registers depending on compiler,
98   // Rewrite this in assembly to really clobber all registers.
99   // GCC for ia32 uses the FPU and does not touch XMM registers.
100   return x1 * 1.01 + x2 * 2.02 + x3 * 3.03 + x4 * 4.04;
101 }
102 
103 
104 }  // namespace internal
105 }  // namespace v8
106