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