2012-04-13 09:38:00 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_ARGUMENTS_H_
|
|
|
|
#define V8_ARGUMENTS_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
2014-07-07 07:04:16 +00:00
|
|
|
#include "src/isolate.h"
|
2011-05-06 06:50:20 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Arguments provides access to runtime call parameters.
|
|
|
|
//
|
|
|
|
// It uses the fact that the instance fields of Arguments
|
|
|
|
// (length_, arguments_) are "overlayed" with the parameters
|
|
|
|
// (no. of parameters, and the parameter pointer) passed so
|
|
|
|
// that inside the C++ function, the parameters passed can
|
|
|
|
// be accessed conveniently:
|
|
|
|
//
|
|
|
|
// Object* Runtime_function(Arguments args) {
|
|
|
|
// ... use args[i] here ...
|
|
|
|
// }
|
2014-06-06 09:57:08 +00:00
|
|
|
//
|
|
|
|
// Note that length_ (whose value is in the integer range) is defined
|
|
|
|
// as intptr_t to provide endian-neutrality on 64-bit archs.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
class Arguments BASE_EMBEDDED {
|
|
|
|
public:
|
2009-09-30 12:25:46 +00:00
|
|
|
Arguments(int length, Object** arguments)
|
|
|
|
: length_(length), arguments_(arguments) { }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Object*& operator[] (int index) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(0 <= index && index < length_);
|
2013-06-10 14:44:05 +00:00
|
|
|
return *(reinterpret_cast<Object**>(reinterpret_cast<intptr_t>(arguments_) -
|
|
|
|
index * kPointerSize));
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class S> Handle<S> at(int index) {
|
|
|
|
Object** value = &((*this)[index]);
|
|
|
|
// This cast checks that the object we're accessing does indeed have the
|
|
|
|
// expected type.
|
|
|
|
S::cast(*value);
|
|
|
|
return Handle<S>(reinterpret_cast<S**>(value));
|
|
|
|
}
|
|
|
|
|
2011-06-10 12:15:30 +00:00
|
|
|
int smi_at(int index) {
|
|
|
|
return Smi::cast((*this)[index])->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
double number_at(int index) {
|
|
|
|
return (*this)[index]->Number();
|
|
|
|
}
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Get the total number of arguments including the receiver.
|
2014-06-06 09:57:08 +00:00
|
|
|
int length() const { return static_cast<int>(length_); }
|
2009-10-01 06:27:29 +00:00
|
|
|
|
2009-09-30 12:25:46 +00:00
|
|
|
Object** arguments() { return arguments_; }
|
2011-09-08 19:57:14 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
2014-06-06 09:57:08 +00:00
|
|
|
intptr_t length_;
|
2008-07-03 15:10:15 +00:00
|
|
|
Object** arguments_;
|
|
|
|
};
|
|
|
|
|
2009-09-30 12:25:46 +00:00
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
// For each type of callback, we have a list of arguments
|
|
|
|
// They are used to generate the Call() functions below
|
2013-05-21 06:36:24 +00:00
|
|
|
// These aren't included in the list as they have duplicate signatures
|
2013-08-27 11:47:52 +00:00
|
|
|
// F(NamedPropertyEnumeratorCallback, ...)
|
2013-05-21 06:36:24 +00:00
|
|
|
|
|
|
|
#define FOR_EACH_CALLBACK_TABLE_MAPPING_0(F) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(IndexedPropertyEnumeratorCallback, v8::Array) \
|
2013-05-21 06:36:24 +00:00
|
|
|
|
|
|
|
#define FOR_EACH_CALLBACK_TABLE_MAPPING_1(F) \
|
2014-08-20 15:25:13 +00:00
|
|
|
F(NamedPropertyGetterCallback, v8::Value, v8::Local<v8::String>) \
|
|
|
|
F(AccessorNameGetterCallback, v8::Value, v8::Local<v8::Name>) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(NamedPropertyQueryCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Integer, \
|
|
|
|
v8::Local<v8::String>) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(NamedPropertyDeleterCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Boolean, \
|
|
|
|
v8::Local<v8::String>) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(IndexedPropertyGetterCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Value, \
|
|
|
|
uint32_t) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(IndexedPropertyQueryCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Integer, \
|
|
|
|
uint32_t) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(IndexedPropertyDeleterCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Boolean, \
|
|
|
|
uint32_t) \
|
|
|
|
|
|
|
|
#define FOR_EACH_CALLBACK_TABLE_MAPPING_2(F) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(NamedPropertySetterCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Value, \
|
|
|
|
v8::Local<v8::String>, \
|
|
|
|
v8::Local<v8::Value>) \
|
2013-08-27 11:47:52 +00:00
|
|
|
F(IndexedPropertySetterCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Value, \
|
|
|
|
uint32_t, \
|
|
|
|
v8::Local<v8::Value>) \
|
|
|
|
|
|
|
|
#define FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(F) \
|
2014-08-20 15:25:13 +00:00
|
|
|
F(AccessorNameSetterCallback, \
|
2013-05-21 06:36:24 +00:00
|
|
|
void, \
|
2014-08-20 15:25:13 +00:00
|
|
|
v8::Local<v8::Name>, \
|
2013-05-21 06:36:24 +00:00
|
|
|
v8::Local<v8::Value>) \
|
|
|
|
|
|
|
|
|
2010-03-25 17:08:22 +00:00
|
|
|
// Custom arguments replicate a small segment of stack that can be
|
2009-09-30 12:25:46 +00:00
|
|
|
// accessed through an Arguments object the same way the actual stack
|
|
|
|
// can.
|
2013-05-21 06:36:24 +00:00
|
|
|
template<int kArrayLength>
|
|
|
|
class CustomArgumentsBase : public Relocatable {
|
|
|
|
public:
|
|
|
|
virtual inline void IterateInstance(ObjectVisitor* v) {
|
|
|
|
v->VisitPointers(values_, values_ + kArrayLength);
|
|
|
|
}
|
|
|
|
protected:
|
2013-10-01 09:24:13 +00:00
|
|
|
inline Object** begin() { return values_; }
|
2013-05-21 06:36:24 +00:00
|
|
|
explicit inline CustomArgumentsBase(Isolate* isolate)
|
|
|
|
: Relocatable(isolate) {}
|
|
|
|
Object* values_[kArrayLength];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class CustomArguments : public CustomArgumentsBase<T::kArgsLength> {
|
2009-10-01 06:27:29 +00:00
|
|
|
public:
|
2013-05-21 06:36:24 +00:00
|
|
|
static const int kReturnValueOffset = T::kReturnValueIndex;
|
|
|
|
|
|
|
|
typedef CustomArgumentsBase<T::kArgsLength> Super;
|
|
|
|
~CustomArguments() {
|
2013-10-01 09:24:13 +00:00
|
|
|
this->begin()[kReturnValueOffset] =
|
2013-05-21 06:36:24 +00:00
|
|
|
reinterpret_cast<Object*>(kHandleZapValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit inline CustomArguments(Isolate* isolate) : Super(isolate) {}
|
|
|
|
|
|
|
|
template<typename V>
|
|
|
|
v8::Handle<V> GetReturnValue(Isolate* isolate);
|
|
|
|
|
|
|
|
inline Isolate* isolate() {
|
2013-10-01 09:24:13 +00:00
|
|
|
return reinterpret_cast<Isolate*>(this->begin()[T::kIsolateIndex]);
|
2009-09-30 12:25:46 +00:00
|
|
|
}
|
2013-05-21 06:36:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class PropertyCallbackArguments
|
|
|
|
: public CustomArguments<PropertyCallbackInfo<Value> > {
|
|
|
|
public:
|
|
|
|
typedef PropertyCallbackInfo<Value> T;
|
|
|
|
typedef CustomArguments<T> Super;
|
|
|
|
static const int kArgsLength = T::kArgsLength;
|
|
|
|
static const int kThisIndex = T::kThisIndex;
|
|
|
|
static const int kHolderIndex = T::kHolderIndex;
|
2013-09-12 14:32:14 +00:00
|
|
|
static const int kDataIndex = T::kDataIndex;
|
|
|
|
static const int kReturnValueDefaultValueIndex =
|
|
|
|
T::kReturnValueDefaultValueIndex;
|
|
|
|
static const int kIsolateIndex = T::kIsolateIndex;
|
2013-05-21 06:36:24 +00:00
|
|
|
|
|
|
|
PropertyCallbackArguments(Isolate* isolate,
|
|
|
|
Object* data,
|
|
|
|
Object* self,
|
|
|
|
JSObject* holder)
|
|
|
|
: Super(isolate) {
|
2013-10-01 09:24:13 +00:00
|
|
|
Object** values = this->begin();
|
2013-05-21 06:36:24 +00:00
|
|
|
values[T::kThisIndex] = self;
|
|
|
|
values[T::kHolderIndex] = holder;
|
|
|
|
values[T::kDataIndex] = data;
|
|
|
|
values[T::kIsolateIndex] = reinterpret_cast<Object*>(isolate);
|
2013-06-10 07:41:16 +00:00
|
|
|
// Here the hole is set as default value.
|
|
|
|
// It cannot escape into js as it's remove in Call below.
|
|
|
|
values[T::kReturnValueDefaultValueIndex] =
|
|
|
|
isolate->heap()->the_hole_value();
|
2013-05-21 06:36:24 +00:00
|
|
|
values[T::kReturnValueIndex] = isolate->heap()->the_hole_value();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(values[T::kHolderIndex]->IsHeapObject());
|
|
|
|
DCHECK(values[T::kIsolateIndex]->IsSmi());
|
2013-05-21 06:36:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The following Call functions wrap the calling of all callbacks to handle
|
|
|
|
* calling either the old or the new style callbacks depending on which one
|
|
|
|
* has been registered.
|
|
|
|
* For old callbacks which return an empty handle, the ReturnValue is checked
|
|
|
|
* and used if it's been set to anything inside the callback.
|
|
|
|
* New style callbacks always use the return value.
|
|
|
|
*/
|
2013-08-27 11:47:52 +00:00
|
|
|
#define WRITE_CALL_0(Function, ReturnValue) \
|
|
|
|
v8::Handle<ReturnValue> Call(Function f); \
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
#define WRITE_CALL_1(Function, ReturnValue, Arg1) \
|
|
|
|
v8::Handle<ReturnValue> Call(Function f, Arg1 arg1); \
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
#define WRITE_CALL_2(Function, ReturnValue, Arg1, Arg2) \
|
|
|
|
v8::Handle<ReturnValue> Call(Function f, Arg1 arg1, Arg2 arg2); \
|
2013-05-21 06:36:24 +00:00
|
|
|
|
2013-08-27 11:47:52 +00:00
|
|
|
#define WRITE_CALL_2_VOID(Function, ReturnValue, Arg1, Arg2) \
|
|
|
|
void Call(Function f, Arg1 arg1, Arg2 arg2); \
|
2013-05-21 06:36:24 +00:00
|
|
|
|
|
|
|
FOR_EACH_CALLBACK_TABLE_MAPPING_0(WRITE_CALL_0)
|
|
|
|
FOR_EACH_CALLBACK_TABLE_MAPPING_1(WRITE_CALL_1)
|
|
|
|
FOR_EACH_CALLBACK_TABLE_MAPPING_2(WRITE_CALL_2)
|
|
|
|
FOR_EACH_CALLBACK_TABLE_MAPPING_2_VOID_RETURN(WRITE_CALL_2_VOID)
|
|
|
|
|
|
|
|
#undef WRITE_CALL_0
|
|
|
|
#undef WRITE_CALL_1
|
|
|
|
#undef WRITE_CALL_2
|
|
|
|
#undef WRITE_CALL_2_VOID
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FunctionCallbackArguments
|
|
|
|
: public CustomArguments<FunctionCallbackInfo<Value> > {
|
|
|
|
public:
|
|
|
|
typedef FunctionCallbackInfo<Value> T;
|
|
|
|
typedef CustomArguments<T> Super;
|
|
|
|
static const int kArgsLength = T::kArgsLength;
|
2013-09-17 11:37:48 +00:00
|
|
|
static const int kHolderIndex = T::kHolderIndex;
|
2013-09-26 10:28:00 +00:00
|
|
|
static const int kDataIndex = T::kDataIndex;
|
|
|
|
static const int kReturnValueDefaultValueIndex =
|
|
|
|
T::kReturnValueDefaultValueIndex;
|
|
|
|
static const int kIsolateIndex = T::kIsolateIndex;
|
|
|
|
static const int kCalleeIndex = T::kCalleeIndex;
|
|
|
|
static const int kContextSaveIndex = T::kContextSaveIndex;
|
2010-11-01 10:51:44 +00:00
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
FunctionCallbackArguments(internal::Isolate* isolate,
|
|
|
|
internal::Object* data,
|
|
|
|
internal::JSFunction* callee,
|
|
|
|
internal::Object* holder,
|
|
|
|
internal::Object** argv,
|
|
|
|
int argc,
|
|
|
|
bool is_construct_call)
|
|
|
|
: Super(isolate),
|
|
|
|
argv_(argv),
|
|
|
|
argc_(argc),
|
|
|
|
is_construct_call_(is_construct_call) {
|
2013-10-01 09:24:13 +00:00
|
|
|
Object** values = begin();
|
2013-05-21 06:36:24 +00:00
|
|
|
values[T::kDataIndex] = data;
|
|
|
|
values[T::kCalleeIndex] = callee;
|
|
|
|
values[T::kHolderIndex] = holder;
|
2013-09-17 11:37:48 +00:00
|
|
|
values[T::kContextSaveIndex] = isolate->heap()->the_hole_value();
|
2013-05-21 06:36:24 +00:00
|
|
|
values[T::kIsolateIndex] = reinterpret_cast<internal::Object*>(isolate);
|
2013-06-10 07:41:16 +00:00
|
|
|
// Here the hole is set as default value.
|
|
|
|
// It cannot escape into js as it's remove in Call below.
|
|
|
|
values[T::kReturnValueDefaultValueIndex] =
|
|
|
|
isolate->heap()->the_hole_value();
|
2013-05-21 06:36:24 +00:00
|
|
|
values[T::kReturnValueIndex] = isolate->heap()->the_hole_value();
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(values[T::kCalleeIndex]->IsJSFunction());
|
|
|
|
DCHECK(values[T::kHolderIndex]->IsHeapObject());
|
|
|
|
DCHECK(values[T::kIsolateIndex]->IsSmi());
|
2010-11-01 10:51:44 +00:00
|
|
|
}
|
|
|
|
|
2013-05-21 06:36:24 +00:00
|
|
|
/*
|
|
|
|
* The following Call function wraps the calling of all callbacks to handle
|
|
|
|
* calling either the old or the new style callbacks depending on which one
|
|
|
|
* has been registered.
|
|
|
|
* For old callbacks which return an empty handle, the ReturnValue is checked
|
|
|
|
* and used if it's been set to anything inside the callback.
|
|
|
|
* New style callbacks always use the return value.
|
|
|
|
*/
|
2013-08-27 11:47:52 +00:00
|
|
|
v8::Handle<v8::Value> Call(FunctionCallback f);
|
2012-04-13 09:58:29 +00:00
|
|
|
|
2009-10-01 06:27:29 +00:00
|
|
|
private:
|
2013-05-21 06:36:24 +00:00
|
|
|
internal::Object** argv_;
|
|
|
|
int argc_;
|
|
|
|
bool is_construct_call_;
|
2009-09-30 12:25:46 +00:00
|
|
|
};
|
|
|
|
|
2011-03-30 14:17:39 +00:00
|
|
|
|
2013-11-22 10:21:47 +00:00
|
|
|
double ClobberDoubleRegisters(double x1, double x2, double x3, double x4);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define CLOBBER_DOUBLE_REGISTERS() ClobberDoubleRegisters(1, 2, 3, 4);
|
|
|
|
#else
|
|
|
|
#define CLOBBER_DOUBLE_REGISTERS()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
#define DECLARE_RUNTIME_FUNCTION(Name) \
|
|
|
|
Object* Name(int args_length, Object** args_object, Isolate* isolate)
|
2013-04-30 11:34:43 +00:00
|
|
|
|
2014-05-28 09:49:53 +00:00
|
|
|
#define RUNTIME_FUNCTION_RETURNS_TYPE(Type, Name) \
|
|
|
|
static INLINE(Type __RT_impl_##Name(Arguments args, Isolate* isolate)); \
|
|
|
|
Type Name(int args_length, Object** args_object, Isolate* isolate) { \
|
|
|
|
CLOBBER_DOUBLE_REGISTERS(); \
|
|
|
|
Arguments args(args_length, args_object); \
|
|
|
|
return __RT_impl_##Name(args, isolate); \
|
|
|
|
} \
|
2013-04-30 11:34:43 +00:00
|
|
|
static Type __RT_impl_##Name(Arguments args, Isolate* isolate)
|
|
|
|
|
2014-04-22 12:50:58 +00:00
|
|
|
|
|
|
|
#define RUNTIME_FUNCTION(Name) RUNTIME_FUNCTION_RETURNS_TYPE(Object*, Name)
|
|
|
|
#define RUNTIME_FUNCTION_RETURN_PAIR(Name) \
|
|
|
|
RUNTIME_FUNCTION_RETURNS_TYPE(ObjectPair, Name)
|
|
|
|
|
2013-04-30 11:34:43 +00:00
|
|
|
#define RUNTIME_ARGUMENTS(isolate, args) \
|
|
|
|
args.length(), args.arguments(), isolate
|
2009-09-30 12:25:46 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_ARGUMENTS_H_
|