Chromium Code Reviews| Index: runtime/vm/native_arguments.h |
| =================================================================== |
| --- runtime/vm/native_arguments.h (revision 28015) |
| +++ runtime/vm/native_arguments.h (working copy) |
| @@ -87,48 +87,36 @@ |
| Isolate* isolate() const { return isolate_; } |
| int ArgCount() const { return ArgcBits::decode(argc_tag_); } |
| - // Returns true if the arguments are those of an instance function call. |
| - bool ToInstanceFunction() const { |
| - return InstanceFunctionBit::decode(argc_tag_); |
| - } |
| - |
| - // Returns true if the arguments are those of a closure function call. |
| - bool ToClosureFunction() const { |
| - return ClosureFunctionBit::decode(argc_tag_); |
| - } |
| - |
| 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(); |
| + int function_bits = FunctionBits::decode(argc_tag_); |
| + return ArgCount() - NumHiddenArgs(function_bits); |
| } |
| - RawObject* NativeArgAt(int index) const { |
| - ASSERT((index >= 0) && (index < NativeArgCount())); |
| - if ((index == 0) && ToClosureFunction() && ToInstanceFunction()) { |
| + RawObject* NativeReceiver() const { |
| + int function_bits = FunctionBits::decode(argc_tag_); |
| + if (function_bits == (kClosureFunctionBit | kInstanceFunctionBit)) { |
| // Retrieve the receiver from the context. |
| const Context& context = Context::Handle(isolate_->top_context()); |
| return context.At(0); |
| - } else { |
| - const int actual_index = index + NumHiddenArgs(); |
| - return ArgAt(actual_index); |
| } |
| + return ArgAt(NumHiddenArgs(function_bits)); |
| } |
| + RawObject* NativeArgAt(int index) const { |
| + ASSERT((index >= 0) && (index < NativeArgCount())); |
| + if (index == 0) { |
| + return NativeReceiver(); |
|
regis
2013/09/27 19:34:39
I would add a comment that calling NativeReceiver(
siva
2013/09/27 21:12:37
Good point.
As discussed offline I have added a p
|
| + } |
| + int function_bits = FunctionBits::decode(argc_tag_); |
| + const int actual_index = index + NumHiddenArgs(function_bits); |
| + return ArgAt(actual_index); |
| + } |
| + |
| void SetReturn(const Object& value) const { |
| *retval_ = value.raw(); |
| } |
| @@ -162,21 +150,29 @@ |
| ASSERT(function.is_native()); |
| ASSERT(!function.IsConstructor()); // Not supported. |
| int tag = ArgcBits::encode(function.NumParameters()); |
| - tag = InstanceFunctionBit::update(!function.is_static(), tag); |
| - tag = ClosureFunctionBit::update(function.IsClosureFunction(), tag); |
| - return tag; |
| + int function_bits = 0; |
| + if (!function.is_static()) { |
| + function_bits |= kInstanceFunctionBit; |
| + } |
| + if (function.IsClosureFunction()) { |
| + function_bits |= kClosureFunctionBit; |
| + } |
| + return FunctionBits::update(function_bits, tag); |
| } |
| private: |
| + enum { |
| + kInstanceFunctionBit = 1, |
| + kClosureFunctionBit = 2, |
| + }; |
| enum ArgcTagBits { |
| kArgcBit = 0, |
| kArgcSize = 24, |
| - kInstanceFunctionBit = 24, |
| - kClosureFunctionBit = 25, |
| + kFunctionBit = 24, |
| + kFunctionSize = 2, |
| }; |
| class ArgcBits : public BitField<int, kArgcBit, kArgcSize> {}; |
| - class InstanceFunctionBit : public BitField<bool, kInstanceFunctionBit, 1> {}; |
| - class ClosureFunctionBit : public BitField<bool, kClosureFunctionBit, 1> {}; |
| + class FunctionBits : public BitField<int, kFunctionBit, kFunctionSize> {}; |
| friend class Api; |
| friend class BootstrapNatives; |
| friend class Simulator; |
| @@ -189,6 +185,27 @@ |
| *retval_ = value; |
| } |
| + // Returns true if the arguments are those of an instance function call. |
| + bool ToInstanceFunction() const { |
| + return (FunctionBits::decode(argc_tag_) & kInstanceFunctionBit); |
| + } |
| + |
| + // Returns true if the arguments are those of a closure function call. |
| + bool ToClosureFunction() const { |
| + return (FunctionBits::decode(argc_tag_) & kClosureFunctionBit); |
| + } |
| + |
| + int NumHiddenArgs(int function_bits) 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 (function_bits == kClosureFunctionBit) { |
| + return 1; |
| + } |
| + return 0; |
| + } |
| + |
| Isolate* isolate_; // Current isolate pointer. |
| int argc_tag_; // Encodes argument count and invoked native call type. |
| RawObject*(*argv_)[]; // Pointer to an array of arguments to runtime call. |