Commit fbdcbdf7 authored by serya@chromium.org's avatar serya@chromium.org

Refactoring of v8:Arguments similary we did with v8::AccessorInfo...

Refactoring of v8:Arguments similary we did with v8::AccessorInfo (http://codereview.chromium.org/242050). GC-controlled values moved to a separate array.
Review URL: http://codereview.chromium.org/4117010

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5746 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 51bc9a14
...@@ -1790,18 +1790,19 @@ class Arguments { ...@@ -1790,18 +1790,19 @@ class Arguments {
inline bool IsConstructCall() const; inline bool IsConstructCall() const;
inline Local<Value> Data() const; inline Local<Value> Data() const;
private: private:
static const int kDataIndex = 0;
static const int kCalleeIndex = -1;
static const int kHolderIndex = -2;
friend class ImplementationUtilities; friend class ImplementationUtilities;
inline Arguments(Local<Value> data, inline Arguments(internal::Object** implicit_args,
Local<Object> holder, internal::Object** values,
Local<Function> callee, int length,
bool is_construct_call, bool is_construct_call);
void** values, int length); internal::Object** implicit_args_;
Local<Value> data_; internal::Object** values_;
Local<Object> holder_;
Local<Function> callee_;
bool is_construct_call_;
void** values_;
int length_; int length_;
bool is_construct_call_;
}; };
...@@ -3470,14 +3471,13 @@ void Persistent<T>::ClearWeak() { ...@@ -3470,14 +3471,13 @@ void Persistent<T>::ClearWeak() {
} }
Arguments::Arguments(v8::Local<v8::Value> data, Arguments::Arguments(internal::Object** implicit_args,
v8::Local<v8::Object> holder, internal::Object** values, int length,
v8::Local<v8::Function> callee, bool is_construct_call)
bool is_construct_call, : implicit_args_(implicit_args),
void** values, int length) values_(values),
: data_(data), holder_(holder), callee_(callee), length_(length),
is_construct_call_(is_construct_call), is_construct_call_(is_construct_call) { }
values_(values), length_(length) { }
Local<Value> Arguments::operator[](int i) const { Local<Value> Arguments::operator[](int i) const {
...@@ -3487,7 +3487,8 @@ Local<Value> Arguments::operator[](int i) const { ...@@ -3487,7 +3487,8 @@ Local<Value> Arguments::operator[](int i) const {
Local<Function> Arguments::Callee() const { Local<Function> Arguments::Callee() const {
return callee_; return Local<Function>(reinterpret_cast<Function*>(
&implicit_args_[kCalleeIndex]));
} }
...@@ -3497,12 +3498,13 @@ Local<Object> Arguments::This() const { ...@@ -3497,12 +3498,13 @@ Local<Object> Arguments::This() const {
Local<Object> Arguments::Holder() const { Local<Object> Arguments::Holder() const {
return holder_; return Local<Object>(reinterpret_cast<Object*>(
&implicit_args_[kHolderIndex]));
} }
Local<Value> Arguments::Data() const { Local<Value> Arguments::Data() const {
return data_; return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));
} }
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#define V8_APIUTILS_H_ #define V8_APIUTILS_H_
namespace v8 { namespace v8 {
class ImplementationUtilities { class ImplementationUtilities {
public: public:
static v8::Handle<v8::Primitive> Undefined(); static v8::Handle<v8::Primitive> Undefined();
...@@ -45,12 +44,21 @@ class ImplementationUtilities { ...@@ -45,12 +44,21 @@ class ImplementationUtilities {
return that->names_; return that->names_;
} }
static v8::Arguments NewArguments(Local<Value> data, // Packs additional parameters for the NewArguments function. |implicit_args|
Local<Object> holder, // is a pointer to the last element of 3-elements array controlled by GC.
Local<Function> callee, static void PrepareArgumentsData(internal::Object** implicit_args,
bool is_construct_call, internal::Object* data,
void** argv, int argc) { internal::JSFunction* callee,
return v8::Arguments(data, holder, callee, is_construct_call, argv, argc); internal::Object* holder) {
implicit_args[v8::Arguments::kDataIndex] = data;
implicit_args[v8::Arguments::kCalleeIndex] = callee;
implicit_args[v8::Arguments::kHolderIndex] = holder;
}
static v8::Arguments NewArguments(internal::Object** implicit_args,
internal::Object** argv, int argc,
bool is_construct_call) {
return v8::Arguments(implicit_args, argv, argc, is_construct_call);
} }
// Introduce an alias for the handle scope data to allow non-friends // Introduce an alias for the handle scope data to allow non-friends
......
...@@ -84,6 +84,15 @@ class CustomArguments : public Relocatable { ...@@ -84,6 +84,15 @@ class CustomArguments : public Relocatable {
values_[1] = holder; values_[1] = holder;
values_[0] = data; values_[0] = data;
} }
inline CustomArguments() {
#ifdef DEBUG
for (size_t i = 0; i < ARRAY_SIZE(values_); i++) {
values_[i] = reinterpret_cast<Object*>(kZapValue);
}
#endif
}
void IterateInstance(ObjectVisitor* v); void IterateInstance(ObjectVisitor* v);
Object** end() { return values_ + ARRAY_SIZE(values_) - 1; } Object** end() { return values_ + ARRAY_SIZE(values_) - 1; }
private: private:
......
...@@ -1014,20 +1014,18 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper( ...@@ -1014,20 +1014,18 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper(
Object* data_obj = call_data->data(); Object* data_obj = call_data->data();
Object* result; Object* result;
Handle<Object> data_handle(data_obj);
v8::Local<v8::Value> data = v8::Utils::ToLocal(data_handle);
ASSERT(raw_holder->IsJSObject());
v8::Local<v8::Function> callee = v8::Utils::ToLocal(function);
Handle<JSObject> holder_handle(JSObject::cast(raw_holder));
v8::Local<v8::Object> holder = v8::Utils::ToLocal(holder_handle);
LOG(ApiObjectAccess("call", JSObject::cast(*args.receiver()))); LOG(ApiObjectAccess("call", JSObject::cast(*args.receiver())));
ASSERT(raw_holder->IsJSObject());
CustomArguments custom;
v8::ImplementationUtilities::PrepareArgumentsData(custom.end(),
data_obj, *function, raw_holder);
v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( v8::Arguments new_args = v8::ImplementationUtilities::NewArguments(
data, custom.end(),
holder, &args[0] - 1,
callee, args.length() - 1,
is_construct, is_construct);
reinterpret_cast<void**>(&args[0] - 1),
args.length() - 1);
v8::Handle<v8::Value> value; v8::Handle<v8::Value> value;
{ {
...@@ -1089,26 +1087,22 @@ BUILTIN(FastHandleApiCall) { ...@@ -1089,26 +1087,22 @@ BUILTIN(FastHandleApiCall) {
Handle<JSFunction> function = args.at<JSFunction>(args_length); Handle<JSFunction> function = args.at<JSFunction>(args_length);
Object* callback_obj = args[args_length + 1]; Object* callback_obj = args[args_length + 1];
Handle<Object> data_handle = args.at<Object>(args_length + 2); Handle<Object> data = args.at<Object>(args_length + 2);
Handle<JSObject> checked_holder = args.at<JSObject>(args_length + 3); Handle<JSObject> checked_holder = args.at<JSObject>(args_length + 3);
#ifdef DEBUG #ifdef DEBUG
VerifyTypeCheck(checked_holder, function); VerifyTypeCheck(checked_holder, function);
#endif #endif
v8::Local<v8::Object> holder = v8::Utils::ToLocal(checked_holder); CustomArguments custom;
v8::Local<v8::Function> callee = v8::Utils::ToLocal(function); v8::ImplementationUtilities::PrepareArgumentsData(custom.end(),
v8::InvocationCallback callback = *data, *function, *checked_holder);
v8::ToCData<v8::InvocationCallback>(callback_obj);
v8::Local<v8::Value> data = v8::Utils::ToLocal(data_handle);
v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( v8::Arguments new_args = v8::ImplementationUtilities::NewArguments(
data, custom.end(),
holder, &args[0] - 1,
callee, args_length - 1,
is_construct, is_construct);
reinterpret_cast<void**>(&args[0] - 1),
args_length - 1);
HandleScope scope; HandleScope scope;
Object* result; Object* result;
...@@ -1119,6 +1113,9 @@ BUILTIN(FastHandleApiCall) { ...@@ -1119,6 +1113,9 @@ BUILTIN(FastHandleApiCall) {
#ifdef ENABLE_LOGGING_AND_PROFILING #ifdef ENABLE_LOGGING_AND_PROFILING
state.set_external_callback(v8::ToCData<Address>(callback_obj)); state.set_external_callback(v8::ToCData<Address>(callback_obj));
#endif #endif
v8::InvocationCallback callback =
v8::ToCData<v8::InvocationCallback>(callback_obj);
value = callback(new_args); value = callback(new_args);
} }
if (value.IsEmpty()) { if (value.IsEmpty()) {
...@@ -1161,23 +1158,20 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor( ...@@ -1161,23 +1158,20 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallAsFunctionOrConstructor(
v8::ToCData<v8::InvocationCallback>(callback_obj); v8::ToCData<v8::InvocationCallback>(callback_obj);
// Get the data for the call and perform the callback. // Get the data for the call and perform the callback.
Object* data_obj = call_data->data();
Object* result; Object* result;
{ HandleScope scope; {
v8::Local<v8::Object> self = HandleScope scope;
v8::Utils::ToLocal(Handle<JSObject>::cast(args.receiver()));
Handle<Object> data_handle(data_obj); LOG(ApiObjectAccess("call non-function", obj));
v8::Local<v8::Value> data = v8::Utils::ToLocal(data_handle);
Handle<JSFunction> callee_handle(constructor); CustomArguments custom;
v8::Local<v8::Function> callee = v8::Utils::ToLocal(callee_handle); v8::ImplementationUtilities::PrepareArgumentsData(custom.end(),
LOG(ApiObjectAccess("call non-function", JSObject::cast(*args.receiver()))); call_data->data(), constructor, obj);
v8::Arguments new_args = v8::ImplementationUtilities::NewArguments( v8::Arguments new_args = v8::ImplementationUtilities::NewArguments(
data, custom.end(),
self, &args[0] - 1,
callee, args.length() - 1,
is_construct_call, is_construct_call);
reinterpret_cast<void**>(&args[0] - 1),
args.length() - 1);
v8::Handle<v8::Value> value; v8::Handle<v8::Value> value;
{ {
// Leaving JavaScript. // Leaving JavaScript.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment