From 87fbbd5dfc109513ffeec5b5f1ce2ed758070aab Mon Sep 17 00:00:00 2001 From: "christian.plesner.hansen@gmail.com" Date: Wed, 30 Sep 2009 12:25:46 +0000 Subject: [PATCH] Changed structure of accessor arguments passing to allow accessor callbacks to be called directly from native code. Review URL: http://codereview.chromium.org/242050 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2995 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 41 ++++++------- src/api.cc | 1 + src/arguments.h | 26 ++++++++ src/handles.cc | 20 +++--- src/heap.cc | 6 +- src/objects.cc | 152 ++++++++++++++++++++++++---------------------- src/objects.h | 31 ++++++++-- src/stub-cache.cc | 41 ++++--------- src/v8threads.cc | 6 +- 9 files changed, 184 insertions(+), 140 deletions(-) diff --git a/include/v8.h b/include/v8.h index ca3bfefa3..2232cb99d 100644 --- a/include/v8.h +++ b/include/v8.h @@ -130,6 +130,7 @@ class Data; namespace internal { class Object; +class Arguments; } @@ -1408,17 +1409,13 @@ class V8EXPORT Arguments { */ class V8EXPORT AccessorInfo { public: - inline AccessorInfo(Local self, - Local data, - Local holder) - : self_(self), data_(data), holder_(holder) { } + inline AccessorInfo(internal::Object** args) + : args_(args) { } inline Local Data() const; inline Local This() const; inline Local Holder() const; private: - Local self_; - Local data_; - Local holder_; + internal::Object** args_; }; @@ -2873,21 +2870,6 @@ int Arguments::Length() const { } -Local AccessorInfo::Data() const { - return data_; -} - - -Local AccessorInfo::This() const { - return self_; -} - - -Local AccessorInfo::Holder() const { - return holder_; -} - - template Local HandleScope::Close(Handle value) { internal::Object** before = reinterpret_cast(*value); @@ -3085,6 +3067,21 @@ External* External::Cast(v8::Value* value) { } +Local AccessorInfo::Data() const { + return Local(reinterpret_cast(&args_[-3])); +} + + +Local AccessorInfo::This() const { + return Local(reinterpret_cast(&args_[0])); +} + + +Local AccessorInfo::Holder() const { + return Local(reinterpret_cast(&args_[-1])); +} + + /** * \example shell.cc * A simple shell that takes a list of expressions on the diff --git a/src/api.cc b/src/api.cc index c859f12a0..f8c8978ad 100644 --- a/src/api.cc +++ b/src/api.cc @@ -28,6 +28,7 @@ #include "v8.h" #include "api.h" +#include "arguments.h" #include "bootstrapper.h" #include "compiler.h" #include "debug.h" diff --git a/src/arguments.h b/src/arguments.h index 80f90063b..fbd82128c 100644 --- a/src/arguments.h +++ b/src/arguments.h @@ -45,6 +45,9 @@ namespace internal { class Arguments BASE_EMBEDDED { public: + Arguments(int length, Object** arguments) + : length_(length), arguments_(arguments) { } + Object*& operator[] (int index) { ASSERT(0 <= index && index < length_); return arguments_[-index]; @@ -60,12 +63,35 @@ class Arguments BASE_EMBEDDED { // Get the total number of arguments including the receiver. int length() const { return length_; } + + Object** arguments() { return arguments_; } private: int length_; Object** arguments_; }; + +// Cursom arguments replicate a small segment of stack that can be +// accessed through an Arguments object the same way the actual stack +// can. +class CustomArguments : public Relocatable { +public: + inline CustomArguments(Object *data, + JSObject *self, + JSObject *holder) { + values_[3] = self; + values_[2] = holder; + values_[1] = Smi::FromInt(0); + values_[0] = data; + } + void IterateInstance(ObjectVisitor* v); + Object** end() { return values_ + 3; } +private: + Object* values_[4]; +}; + + } } // namespace v8::internal #endif // V8_ARGUMENTS_H_ diff --git a/src/handles.cc b/src/handles.cc index ba57629e7..b43ec5320 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -29,6 +29,7 @@ #include "accessors.h" #include "api.h" +#include "arguments.h" #include "bootstrapper.h" #include "compiler.h" #include "debug.h" @@ -479,15 +480,17 @@ int GetScriptLineNumber(Handle