V8 Project
arguments.cc
Go to the documentation of this file.
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/v8.h"
6 
7 #include "src/arguments.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>
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::Handle<V>();
21  return Utils::Convert<Object, V>(Handle<Object>(handle));
22 }
23 
24 
26  Isolate* isolate = this->isolate();
28  ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f));
30  argv_,
31  argc_,
33  f(info);
34  return GetReturnValue<v8::Value>(isolate);
35 }
36 
37 
38 #define WRITE_CALL_0(Function, ReturnValue) \
39 v8::Handle<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::Handle<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::Handle<ReturnValue> PropertyCallbackArguments::Call(Function f, \
63  Arg1 arg1, \
64  Arg2 arg2) { \
65  Isolate* isolate = this->isolate(); \
66  VMState<EXTERNAL> state(isolate); \
67  ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
68  PropertyCallbackInfo<ReturnValue> info(begin()); \
69  f(arg1, arg2, info); \
70  return GetReturnValue<ReturnValue>(isolate); \
71 }
72 
73 
74 #define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \
75 void PropertyCallbackArguments::Call(Function f, \
76  Arg1 arg1, \
77  Arg2 arg2) { \
78  Isolate* isolate = this->isolate(); \
79  VMState<EXTERNAL> state(isolate); \
80  ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); \
81  PropertyCallbackInfo<ReturnValue> info(begin()); \
82  f(arg1, arg2, info); \
83 }
84 
85 
90 
91 #undef WRITE_CALL_0
92 #undef WRITE_CALL_1
93 #undef WRITE_CALL_2
94 #undef WRITE_CALL_2_VOID
95 
96 
97 double ClobberDoubleRegisters(double x1, double x2, double x3, double x4) {
98  // TODO(ulan): This clobbers only subset of registers depending on compiler,
99  // Rewrite this in assembly to really clobber all registers.
100  // GCC for ia32 uses the FPU and does not touch XMM registers.
101  return x1 * 1.01 + x2 * 2.02 + x3 * 3.03 + x4 * 4.04;
102 }
103 
104 
105 } } // namespace v8::internal
#define WRITE_CALL_0(Function, ReturnValue)
Definition: arguments.cc:38
#define WRITE_CALL_1(Function, ReturnValue, Arg1)
Definition: arguments.cc:49
#define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2)
Definition: arguments.cc:61
#define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2)
Definition: arguments.cc:74
#define FOR_EACH_CALLBACK_TABLE_MAPPING_2(F)
Definition: arguments.h:94
#define FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(F)
Definition: arguments.h:104
#define FOR_EACH_CALLBACK_TABLE_MAPPING_0(F)
Definition: arguments.h:72
#define FOR_EACH_CALLBACK_TABLE_MAPPING_1(F)
Definition: arguments.h:75
The argument information given to function call callbacks.
Definition: v8.h:2650
An object reference managed by the v8 garbage collector.
Definition: v8.h:198
v8::Handle< V > GetReturnValue(Isolate *isolate)
Definition: arguments.cc:16
v8::Handle< v8::Value > Call(FunctionCallback f)
Definition: arguments.cc:25
#define FUNCTION_ADDR(f)
Definition: globals.h:195
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4)
Definition: arguments.cc:97
Handle< T > handle(T *t, Isolate *isolate)
Definition: handles.h:146
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20
void(* FunctionCallback)(const FunctionCallbackInfo< Value > &info)
Definition: v8.h:2717