Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: runtime/vm/native_arguments.h

Issue 11293290: Fix native argument handling (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/exceptions_test.cc ('k') | runtime/vm/native_entry.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/native_arguments.h
===================================================================
--- runtime/vm/native_arguments.h (revision 14922)
+++ runtime/vm/native_arguments.h (working copy)
@@ -60,7 +60,7 @@
class NativeArguments {
public:
Isolate* isolate() const { return isolate_; }
- int Count() const { return ArgcBits::decode(argc_tag_); }
+ int ArgCount() const { return ArgcBits::decode(argc_tag_); }
// Returns true if the arguments are those of an instance function call.
bool ToInstanceFunction() const {
@@ -72,11 +72,39 @@
return ClosureFunctionBit::decode(argc_tag_);
}
- RawObject* At(int index) const {
- ASSERT(index >=0 && index < Count());
+ RawObject* ArgAt(int index) const {
+ ASSERT((index >= 0) && (index < ArgCount()));
return (*argv_)[-index];
}
+ int NumHiddenArgs() const {
+ // For static closure functions, the closure at index 0 is hidden.
+ // In the instance closure function case, the receiver is accessed from
+ // the context and the closure at index 0 is hidden, so the apparent
+ // argument count remains unchanged.
+ if (ToClosureFunction() && !ToInstanceFunction()) {
+ return 1;
+ }
+ return 0;
+ }
+
+ int NativeArgCount() const {
+ return ArgCount() - NumHiddenArgs();
+ }
+
+ RawObject* NativeArgAt(int index) const {
+ const int num_hidden_args = NumHiddenArgs();
+ const int actual_index = index + num_hidden_args;
+ ASSERT((actual_index >= num_hidden_args) && (index < ArgCount()));
+ if ((index == 0) && ToClosureFunction() && ToInstanceFunction()) {
+ // Retrieve the receiver from the context.
+ const Context& context = Context::Handle(isolate_->top_context());
+ return context.At(0);
+ } else {
+ return ArgAt(actual_index);
+ }
+ }
+
void SetReturn(const Object& value) const;
static intptr_t isolate_offset() {
« no previous file with comments | « runtime/vm/exceptions_test.cc ('k') | runtime/vm/native_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698