Provide more control about the target object/namespace where a v8 module is registered to.

This commit is contained in:
Oliver Buchtala 2012-11-22 22:50:50 +01:00
commit 008adca72f
2 changed files with 6 additions and 4 deletions

View file

@ -386,12 +386,11 @@ fail:
%{
extern "C" {
void $jsname_initialize(v8::Handle<v8::Context> context)
void $jsname_initialize(v8::Handle<v8::Context> context, v8::Handle<v8::Object> global_obj)
{
SWIG_InitializeModule(0);
v8::HandleScope scope;
v8::Local<v8::Object> global_obj = context->Global();
// a class template for creating proxies of undefined types
SWIGV8_SWIGTYPE_Proxy_class_templ = SWIGV8_CreateClassTemplate("SwigProxy");

View file

@ -9,7 +9,7 @@
#include "js_shell.h"
typedef int (*V8ExtensionRegistrar) (v8::Handle<v8::Context>);
typedef int (*V8ExtensionRegistrar) (v8::Handle<v8::Context>, v8::Handle<v8::Object>);
class V8Shell: public JSShell {
@ -153,10 +153,13 @@ bool V8Shell::InitializeEngine() {
void V8Shell::ExtendEngine() {
v8::HandleScope scope;
v8::Local<v8::Object> global = context->Global();
// register extensions
for(std::vector<V8ExtensionRegistrar>::iterator it=module_initializers.begin();
it != module_initializers.end(); ++it) {
(*it)(context);
(*it)(context, global);
}
}