1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef XWALK_EXTENSIONS_RENDERER_XWALK_JS_MODULE_H_
6 #define XWALK_EXTENSIONS_RENDERER_XWALK_JS_MODULE_H_
9 #include "xwalk/extensions/renderer/xwalk_module_system.h"
12 namespace extensions {
14 scoped_ptr<XWalkNativeModule> CreateJSModuleFromResource(int resource_id);
16 // Provides a module for the Module System based on a JavaScript code. This is
17 // useful for providing JS helpers and small libraries to extensions creators.
19 // The JS code of a native module is executed with an object "exports" that
20 // should be filled with functions and properties that the module will export.
21 class XWalkJSModule : public XWalkNativeModule {
23 explicit XWalkJSModule(const std::string& js_code);
24 virtual ~XWalkJSModule();
27 // XWalkNativeModule implementation.
28 v8::Handle<v8::Object> NewInstance() override;
30 bool Compile(v8::Isolate* isolate, std::string* error);
33 v8::Persistent<v8::Script> compiled_script_;
36 } // namespace extensions
39 #endif // XWALK_EXTENSIONS_RENDERER_XWALK_JS_MODULE_H_