Hi, I'm interested in learning how to get the window object map to the
"global" object in particular correctly. As I said, I can't edit the
JavaScript file being loaded (as it's not mine and I didn't mention
that it's also in source control and this code would be part of a
build/verification tool, and I'm sure that it would be a slippery
slope of one tiny fix after another). And although I could pre-load a
JavaScript file with 'fixes" as I also had mentioned, I'd like to
learn how to do this in C++ first, before I resort to a JavaScript
solution.
I've continued to explore and believe I've gotten closer to a working
solution. I'm not sure if it's correct, but the JavaScript code now
loads. :)
Handle<Object> v8RealGlobal = Handle<Object>::Cast(context->Global()-
>GetPrototype());
Context::Scope context_scope(context);
Local<ObjectTemplate> docTmpl = ObjectTemplate::New();
docTmpl->SetNamedPropertyHandler(MapGet, MapSet);
Local<Object> docObj = docTmpl->NewInstance();
v8RealGlobal->Set(String::New("document"), docObj);
// this appears to work -- grab the prototype from the context global
and assign it to the global variable named "window"
v8RealGlobal->Set(String::New("window"), v8RealGlobal);
The code then loads the scripts.
And then very simple MapGet/Set functions:
Handle<Value> MapGet(Local<String> name, const AccessorInfo& info) {
return Object::New();
}
Handle<Value> MapSet(Local<String> name,
Local<Value> value_obj,
const AccessorInfo& info)
{
return value_obj;
}
Thanks!
--Aaron
http://www.wiredprairie.us