| {# | |
| # Copyright 2015 Google Inc. All Rights Reserved. | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| #} | |
| {% extends "interface-base.h.template" %} | |
| {% block includes %} | |
| {{ super() }} | |
| #include "base/threading/thread_local_storage.h" | |
| #include "cobalt/script/javascriptcore/jsc_global_object.h" | |
| #include "cobalt/script/javascriptcore/script_object_registry.h" | |
| #include "cobalt/script/javascriptcore/thread_local_hash_table.h" | |
| #include "cobalt/script/javascriptcore/wrapper_base.h" | |
| #include "cobalt/script/javascriptcore/wrapper_factory.h" | |
| #include "third_party/WebKit/Source/JavaScriptCore/config.h" | |
| #include "third_party/WebKit/Source/JavaScriptCore/runtime/ClassInfo.h" | |
| {% if is_exception_interface %} | |
| #include "third_party/WebKit/Source/JavaScriptCore/runtime/ErrorInstance.h" | |
| {% endif %} | |
| #include "third_party/WebKit/Source/JavaScriptCore/runtime/JSObject.h" | |
| #include "third_party/WebKit/Source/JavaScriptCore/runtime/Lookup.h" | |
| {% endblock includes%} | |
| {% block implementation %} | |
| class {{binding_class}} | |
| {% if is_global_interface %} | |
| : public script::javascriptcore::JSCGlobalObject { | |
| typedef script::javascriptcore::JSCGlobalObject BaseClass; | |
| {% elif is_exception_interface %} | |
| : public script::javascriptcore::ExceptionBase { | |
| typedef script::javascriptcore::ExceptionBase BaseClass; | |
| {% elif parent_interface %} | |
| : public {{parent_interface}} { | |
| typedef {{parent_interface}} BaseClass; | |
| {% else %} | |
| : public script::javascriptcore::InterfaceBase { | |
| typedef script::javascriptcore::InterfaceBase BaseClass; | |
| {% endif %} | |
| public: | |
| // Get the prototype object for this wrapper class. | |
| static JSC::JSObject* GetPrototype(JSC::JSGlobalObject* global_object); | |
| {% if has_interface_object %} | |
| // Get the interface object for this wrapper class. | |
| static JSC::JSObject* GetConstructor(JSC::ExecState* exec_state); | |
| {% endif %} | |
| {% if named_constructor %} | |
| // Get the named constructor for this wrapper class. | |
| static JSC::JSObject* GetNamedConstructor(JSC::ExecState* exec_state); | |
| {% endif %} | |
| // JavaScriptCore functions and members | |
| DECLARE_CLASSINFO(); | |
| // Needed when JSC::OverridesGetOwnPropertySlot StructureFlag is set | |
| // Must be public so that it can be accessible from getStaticValueSlot<>. | |
| static bool getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, | |
| JSC::PropertyName, | |
| JSC::PropertySlot&); | |
| {% if indexed_property_getter or named_property_getter %} | |
| static bool getOwnPropertySlotByIndex(JSC::JSCell* cell, | |
| JSC::ExecState* exec_state, | |
| uint32_t index, | |
| JSC::PropertySlot& slot); | |
| static void getOwnPropertyNames(JSC::JSObject*, JSC::ExecState*, | |
| JSC::PropertyNameArray&, | |
| JSC::EnumerationMode); | |
| {% endif %} | |
| {% if indexed_property_setter or named_property_setter %} | |
| static void putByIndex(JSC::JSCell* cell, JSC::ExecState* exec_state, | |
| uint32_t index, JSC::JSValue value, bool should_throw); | |
| {% endif %} | |
| // static override. Needed to support setting a property. | |
| static void put(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, | |
| JSC::JSValue, JSC::PutPropertySlot&); | |
| {% if supports_named_properties %} | |
| static bool deleteProperty(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName); | |
| {% endif %} | |
| {% if supports_indexed_properties or supports_named_properties %} | |
| static bool deletePropertyByIndex(JSC::JSCell*, JSC::ExecState*, uint32_t); | |
| {% endif %} | |
| // static override. This function will be called after a new object has | |
| // been created. | |
| void finishCreation(JSC::JSGlobalData& global_data); | |
| {% if not is_global_interface %} | |
| static script::javascriptcore::WrapperFactory::CreateWrapperFunction | |
| GetCreateWrapperFunction() { | |
| return base::Bind(&Create); | |
| } | |
| private: | |
| // Create a new wrapper for |wrappable|, which will be cast to {{impl_class}}. | |
| static JSC::JSObject* Create( | |
| script::javascriptcore::JSCGlobalObject* global_object, | |
| const scoped_refptr<script::Wrappable>& wrappable); | |
| {% else %} | |
| static script::javascriptcore::JSCGlobalObject* Create( | |
| const scoped_refptr<{{impl_class}}>& global_interface, | |
| script::EnvironmentSettings* environment_settings, | |
| JSC::JSGlobalData* global_data, | |
| script::javascriptcore::ScriptObjectRegistry* script_object_registry); | |
| {% endif %} | |
| protected: | |
| static const unsigned StructureFlags = | |
| JSC::OverridesGetOwnPropertySlot | | |
| BaseClass::StructureFlags; | |
| {{binding_class}}( | |
| JSC::JSGlobalData* global_data, | |
| JSC::Structure* structure, | |
| script::javascriptcore::ScriptObjectRegistry* script_object_registry, | |
| {% if is_global_interface %} | |
| scoped_ptr<script::javascriptcore::WrapperFactory> wrapper_factory, | |
| script::EnvironmentSettings* environment_settings, | |
| {% endif %} | |
| const scoped_refptr<{{impl_class}}>& impl); | |
| ~{{binding_class}}(); | |
| {% if add_opaque_roots %} | |
| static void visitChildren(JSC::JSCell* cell, JSC::SlotVisitor& visitor); | |
| {% endif %} | |
| private: | |
| {% if has_interface_object %} | |
| class InterfaceObject; | |
| {% endif %} | |
| {% if named_constructor %} | |
| class NamedInterfaceObject; | |
| {% endif %} | |
| class Prototype; | |
| static const JSC::HashTableValue property_table_values[]; | |
| static const JSC::HashTable property_table_prototype; | |
| static base::LazyInstance< | |
| cobalt::script::javascriptcore::ThreadLocalHashTable> | |
| thread_local_property_table; | |
| static const JSC::HashTable* GetPropertyTable(JSC::ExecState* exec_state); | |
| static bool HasOwnPropertyOrPrototypeProperty(JSC::JSCell* cell, | |
| JSC::ExecState* exec_state, JSC::PropertyName property_name); | |
| #ifdef __LB_SHELL__FORCE_LOGGING__ | |
| struct NonTrivialStaticFields { | |
| // TODO: Only log attempts of usage of unsupported Web APIs. | |
| base::hash_set<std::string> properties_warned_about; | |
| base::Lock lock_; | |
| }; | |
| static base::LazyInstance<NonTrivialStaticFields> non_trivial_static_fields; | |
| #endif // __LB_SHELL__FORCE_LOGGING__ | |
| }; | |
| {% endblock implementation %} |