// This file was GENERATED by command: // pump.py constructor.h.pump // DO NOT EDIT BY HAND!!! // Copyright 2014 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE.chromium file. #ifndef NATIVE_MATE_WRAPPABLE_CLASS_H_ #define NATIVE_MATE_WRAPPABLE_CLASS_H_ #include "base/bind.h" #include "base/compiler_specific.h" #include "native_mate/wrappable.h" #include "native_mate/function_template.h" namespace mate { class WrappableBase; namespace internal { // This set of templates invokes a base::Callback by converting the Arguments // into native types. It relies on the function_template.h to provide helper // templates. inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { return callback.Run(); }; template inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { typename CallbackParamTraits::LocalType a1; if (!GetNextArgument(args, 0, true, &a1)) return nullptr; return callback.Run(a1); }; template inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { typename CallbackParamTraits::LocalType a1; typename CallbackParamTraits::LocalType a2; if (!GetNextArgument(args, 0, true, &a1) || !GetNextArgument(args, 0, false, &a2)) return nullptr; return callback.Run(a1, a2); }; template inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { typename CallbackParamTraits::LocalType a1; typename CallbackParamTraits::LocalType a2; typename CallbackParamTraits::LocalType a3; if (!GetNextArgument(args, 0, true, &a1) || !GetNextArgument(args, 0, false, &a2) || !GetNextArgument(args, 0, false, &a3)) return nullptr; return callback.Run(a1, a2, a3); }; template inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { typename CallbackParamTraits::LocalType a1; typename CallbackParamTraits::LocalType a2; typename CallbackParamTraits::LocalType a3; typename CallbackParamTraits::LocalType a4; if (!GetNextArgument(args, 0, true, &a1) || !GetNextArgument(args, 0, false, &a2) || !GetNextArgument(args, 0, false, &a3) || !GetNextArgument(args, 0, false, &a4)) return nullptr; return callback.Run(a1, a2, a3, a4); }; template inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { typename CallbackParamTraits::LocalType a1; typename CallbackParamTraits::LocalType a2; typename CallbackParamTraits::LocalType a3; typename CallbackParamTraits::LocalType a4; typename CallbackParamTraits::LocalType a5; if (!GetNextArgument(args, 0, true, &a1) || !GetNextArgument(args, 0, false, &a2) || !GetNextArgument(args, 0, false, &a3) || !GetNextArgument(args, 0, false, &a4) || !GetNextArgument(args, 0, false, &a5)) return nullptr; return callback.Run(a1, a2, a3, a4, a5); }; template inline WrappableBase* InvokeFactory( Arguments* args, const base::Callback& callback) { typename CallbackParamTraits::LocalType a1; typename CallbackParamTraits::LocalType a2; typename CallbackParamTraits::LocalType a3; typename CallbackParamTraits::LocalType a4; typename CallbackParamTraits::LocalType a5; typename CallbackParamTraits::LocalType a6; if (!GetNextArgument(args, 0, true, &a1) || !GetNextArgument(args, 0, false, &a2) || !GetNextArgument(args, 0, false, &a3) || !GetNextArgument(args, 0, false, &a4) || !GetNextArgument(args, 0, false, &a5) || !GetNextArgument(args, 0, false, &a6)) return nullptr; return callback.Run(a1, a2, a3, a4, a5, a6); }; } // namespace internal template class Constructor { public: typedef base::Callback WrappableFactoryFunction; Constructor(const base::StringPiece& name) : name_(name) {} virtual ~Constructor() { MATE_PERSISTENT_RESET(constructor_); } v8::Local GetFunctionTemplate( v8::Isolate* isolate, const WrappableFactoryFunction& factory) { if (constructor_.IsEmpty()) { v8::Local constructor = CreateFunctionTemplate( isolate, base::Bind(&Constructor::New, factory)); constructor->InstanceTemplate()->SetInternalFieldCount(1); constructor->SetClassName(StringToV8(isolate, name_)); T::BuildPrototype(isolate, constructor->PrototypeTemplate()); MATE_PERSISTENT_ASSIGN(v8::FunctionTemplate, isolate, constructor_, constructor); } return MATE_PERSISTENT_TO_LOCAL( v8::FunctionTemplate, isolate, constructor_); } private: static MATE_METHOD_RETURN_TYPE New(const WrappableFactoryFunction& factory, v8::Isolate* isolate, Arguments* args) { if (!args->IsConstructCall()) { args->ThrowError("Requires constructor call"); MATE_METHOD_RETURN_UNDEFINED(); } WrappableBase* object; { // Don't continue if the constructor throws an exception. v8::TryCatch try_catch; object = internal::InvokeFactory(args, factory); if (try_catch.HasCaught()) { try_catch.ReThrow(); MATE_METHOD_RETURN_UNDEFINED(); } } if (!object) args->ThrowError(); MATE_METHOD_RETURN_UNDEFINED(); } base::StringPiece name_; v8::Global constructor_; DISALLOW_COPY_AND_ASSIGN(Constructor); }; template WrappableBase* NewOperatorFactory() { return new T; } template v8::Local CreateConstructor( v8::Isolate* isolate, const base::StringPiece& name, const base::Callback& callback) { v8::Local constructor = Constructor(name).GetFunctionTemplate(isolate, callback); return constructor->GetFunction(); } } // namespace mate #endif // NATIVE_MATE_WRAPPABLE_CLASS_H_