// Copyright 2016 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_API_ARGUMENTS_H_ #define V8_API_ARGUMENTS_H_ #include "src/api.h" #include "src/debug/debug.h" #include "src/isolate.h" #include "src/visitors.h" namespace v8 { namespace internal { // Custom arguments replicate a small segment of stack that can be // accessed through an Arguments object the same way the actual stack // can. class CustomArgumentsBase : public Relocatable { protected: explicit inline CustomArgumentsBase(Isolate* isolate); }; template class CustomArguments : public CustomArgumentsBase { public: static const int kReturnValueOffset = T::kReturnValueIndex; ~CustomArguments() override { this->begin()[kReturnValueOffset] = reinterpret_cast(kHandleZapValue); } inline void IterateInstance(RootVisitor* v) override { v->VisitRootPointers(Root::kRelocatable, nullptr, values_, values_ + T::kArgsLength); } protected: explicit inline CustomArguments(Isolate* isolate) : CustomArgumentsBase(isolate) {} template Handle GetReturnValue(Isolate* isolate); inline Isolate* isolate() { return reinterpret_cast(this->begin()[T::kIsolateIndex]); } inline Object** begin() { return values_; } Object* values_[T::kArgsLength]; }; // Note: Calling args.Call() sets the return value on args. For multiple // Call()'s, a new args should be used every time. class PropertyCallbackArguments : public CustomArguments > { public: typedef PropertyCallbackInfo T; typedef CustomArguments Super; static const int kArgsLength = T::kArgsLength; static const int kThisIndex = T::kThisIndex; static const int kHolderIndex = T::kHolderIndex; static const int kDataIndex = T::kDataIndex; static const int kReturnValueDefaultValueIndex = T::kReturnValueDefaultValueIndex; static const int kIsolateIndex = T::kIsolateIndex; static const int kShouldThrowOnErrorIndex = T::kShouldThrowOnErrorIndex; PropertyCallbackArguments(Isolate* isolate, Object* data, Object* self, JSObject* holder, ShouldThrow should_throw); // ------------------------------------------------------------------------- // Accessor Callbacks // Also used for AccessorSetterCallback. inline Handle CallAccessorSetter(Handle info, Handle name, Handle value); // Also used for AccessorGetterCallback, AccessorNameGetterCallback. inline Handle CallAccessorGetter(Handle info, Handle name); // ------------------------------------------------------------------------- // Named Interceptor Callbacks inline Handle CallNamedQuery(Handle interceptor, Handle name); inline Handle CallNamedGetter(Handle interceptor, Handle name); inline Handle CallNamedSetter(Handle interceptor, Handle name, Handle value); inline Handle CallNamedDefiner(Handle interceptor, Handle name, const v8::PropertyDescriptor& desc); inline Handle CallNamedDeleter(Handle interceptor, Handle name); inline Handle CallNamedDescriptor(Handle interceptor, Handle name); inline Handle CallNamedEnumerator( Handle interceptor); // ------------------------------------------------------------------------- // Indexed Interceptor Callbacks inline Handle CallIndexedQuery(Handle interceptor, uint32_t index); inline Handle CallIndexedGetter(Handle interceptor, uint32_t index); inline Handle CallIndexedSetter(Handle interceptor, uint32_t index, Handle value); inline Handle CallIndexedDefiner(Handle interceptor, uint32_t index, const v8::PropertyDescriptor& desc); inline Handle CallIndexedDeleter(Handle interceptor, uint32_t index); inline Handle CallIndexedDescriptor( Handle interceptor, uint32_t index); inline Handle CallIndexedEnumerator( Handle interceptor); private: /* * The following Call functions wrap the calling of all callbacks to handle * calling either the old or the new style callbacks depending on which one * has been registered. * For old callbacks which return an empty handle, the ReturnValue is checked * and used if it's been set to anything inside the callback. * New style callbacks always use the return value. */ inline Handle CallPropertyEnumerator( Handle interceptor); inline Handle BasicCallIndexedGetterCallback( IndexedPropertyGetterCallback f, uint32_t index, Handle info); inline Handle BasicCallNamedGetterCallback( GenericNamedPropertyGetterCallback f, Handle name, Handle info, Handle receiver = Handle()); inline JSObject* holder(); inline Object* receiver(); // Don't copy PropertyCallbackArguments, because they would both have the // same prev_ pointer. DISALLOW_COPY_AND_ASSIGN(PropertyCallbackArguments); }; class FunctionCallbackArguments : public CustomArguments > { public: typedef FunctionCallbackInfo T; typedef CustomArguments Super; static const int kArgsLength = T::kArgsLength; static const int kHolderIndex = T::kHolderIndex; static const int kDataIndex = T::kDataIndex; static const int kReturnValueDefaultValueIndex = T::kReturnValueDefaultValueIndex; static const int kIsolateIndex = T::kIsolateIndex; static const int kNewTargetIndex = T::kNewTargetIndex; FunctionCallbackArguments(internal::Isolate* isolate, internal::Object* data, internal::HeapObject* callee, internal::Object* holder, internal::HeapObject* new_target, internal::Object** argv, int argc); /* * The following Call function wraps the calling of all callbacks to handle * calling either the old or the new style callbacks depending on which one * has been registered. * For old callbacks which return an empty handle, the ReturnValue is checked * and used if it's been set to anything inside the callback. * New style callbacks always use the return value. */ inline Handle Call(CallHandlerInfo* handler); private: inline JSObject* holder(); internal::Object** argv_; int argc_; }; } // namespace internal } // namespace v8 #endif // V8_API_ARGUMENTS_H_