0
0
mirror of https://github.com/phpv8/v8js.git synced 2024-12-22 08:11:52 +00:00

Add Node.js-style "global" to global scope

This commit is contained in:
Stefan Siegl 2016-07-09 15:52:45 +02:00
parent bd730068a2
commit e4ab07de03
No known key found for this signature in database
GPG Key ID: 73942AF5642F3DDA
2 changed files with 25 additions and 4 deletions

View File

@ -0,0 +1,20 @@
--TEST--
Test V8Js::executeString : Global scope links global object
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
$JS = <<< EOT
var_dump(typeof global);
var_dump(global.var_dump === var_dump);
EOT;
$v8 = new V8Js();
$v8->executeString($JS);
?>
===EOF===
--EXPECT--
string(6) "object"
bool(true)
===EOF===

View File

@ -425,14 +425,14 @@ static PHP_METHOD(V8Js, __construct)
/* Create global template for global object */
// Now we are using multiple isolates this needs to be created for every context
v8::Local<v8::ObjectTemplate> tpl = v8::ObjectTemplate::New(c->isolate);
c->global_template.Reset(isolate, tpl);
v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(c->isolate);
c->global_template.Reset(isolate, global_template);
/* Register builtin methods */
v8js_register_methods(tpl, c);
v8js_register_methods(global_template, c);
/* Create context */
v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl);
v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, global_template);
if (exts) {
v8js_free_ext_strarr(exts, exts_count);
@ -447,6 +447,7 @@ static PHP_METHOD(V8Js, __construct)
}
context->SetAlignedPointerInEmbedderData(1, c);
context->Global()->Set(context, V8JS_SYM("global"), context->Global());
c->context.Reset(isolate, context);
/* Enter context */