Convert function.arguments to API-style accessor.

BUG=
R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/256693007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21014 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ulan@chromium.org 2014-04-28 12:02:11 +00:00
parent 87394009b6
commit 7671d9ab66
3 changed files with 39 additions and 31 deletions

View File

@ -1096,26 +1096,47 @@ Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
}
Object* Accessors::FunctionGetArguments(Isolate* isolate,
Object* object,
void*) {
void Accessors::FunctionArgumentsGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
Handle<JSFunction> function;
Handle<Object> object = Utils::OpenHandle(*info.This());
MaybeHandle<JSFunction> maybe_function;
{
DisallowHeapAllocation no_allocation;
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
if (holder == NULL) return isolate->heap()->undefined_value();
function = Handle<JSFunction>(holder, isolate);
JSFunction* function = FindInstanceOf<JSFunction>(isolate, *object);
if (function != NULL) maybe_function = Handle<JSFunction>(function);
}
return *GetFunctionArguments(isolate, function);
Handle<JSFunction> function;
Handle<Object> result;
if (maybe_function.ToHandle(&function)) {
result = GetFunctionArguments(isolate, function);
} else {
result = isolate->factory()->undefined_value();
}
info.GetReturnValue().Set(Utils::ToLocal(result));
}
const AccessorDescriptor Accessors::FunctionArguments = {
FunctionGetArguments,
ReadOnlySetAccessor,
0
};
void Accessors::FunctionArgumentsSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
// Do nothing.
}
Handle<AccessorInfo> Accessors::FunctionArgumentsInfo(
Isolate* isolate, PropertyAttributes attributes) {
return MakeAccessor(isolate,
isolate->factory()->arguments_string(),
&FunctionArgumentsGetter,
&FunctionArgumentsSetter,
attributes);
}
//

View File

@ -37,11 +37,11 @@ namespace internal {
// The list of accessor descriptors. This is a second-order macro
// taking a macro to be applied to all accessor descriptor names.
#define ACCESSOR_DESCRIPTOR_LIST(V) \
V(FunctionArguments) \
V(FunctionCaller) \
V(ArrayLength)
#define ACCESSOR_INFO_LIST(V) \
V(FunctionArguments) \
V(FunctionName) \
V(FunctionLength) \
V(FunctionPrototype) \
@ -114,21 +114,6 @@ class Accessors : public AllStatic {
int* object_offset);
private:
// Accessor functions only used through the descriptor.
static Object* FunctionSetPrototype(Isolate* isolate,
JSObject* object,
Object*,
void*);
static Object* FunctionGetPrototype(Isolate* isolate,
Object* object,
void*);
static Object* FunctionGetLength(Isolate* isolate,
Object* object,
void*);
static Object* FunctionGetName(Isolate* isolate, Object* object, void*);
static Object* FunctionGetArguments(Isolate* isolate,
Object* object,
void*);
static Object* FunctionGetCaller(Isolate* isolate,
Object* object,
void*);

View File

@ -388,7 +388,6 @@ void Genesis::SetFunctionInstanceDescriptor(
int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5;
Map::EnsureDescriptorSlack(map, size);
Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments));
Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller));
PropertyAttributes attribs = static_cast<PropertyAttributes>(
DONT_ENUM | DONT_DELETE | READ_ONLY);
@ -407,8 +406,11 @@ void Genesis::SetFunctionInstanceDescriptor(
name, attribs);
map->AppendDescriptor(&d);
}
Handle<AccessorInfo> args =
Accessors::FunctionArgumentsInfo(isolate(), attribs);
{ // Add arguments.
CallbacksDescriptor d(factory()->arguments_string(), args, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(args->name())),
args, attribs);
map->AppendDescriptor(&d);
}
{ // Add caller.