mirror of
https://github.com/phpv8/v8js.git
synced 2024-12-22 12:51:52 +00:00
Add Node.js-style "global" to global scope
This commit is contained in:
parent
bd730068a2
commit
e4ab07de03
20
tests/global_object_basic.phpt
Normal file
20
tests/global_object_basic.phpt
Normal 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===
|
@ -425,14 +425,14 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
/* Create global template for global object */
|
/* Create global template for global object */
|
||||||
// Now we are using multiple isolates this needs to be created for every context
|
// Now we are using multiple isolates this needs to be created for every context
|
||||||
|
|
||||||
v8::Local<v8::ObjectTemplate> tpl = v8::ObjectTemplate::New(c->isolate);
|
v8::Local<v8::ObjectTemplate> global_template = v8::ObjectTemplate::New(c->isolate);
|
||||||
c->global_template.Reset(isolate, tpl);
|
c->global_template.Reset(isolate, global_template);
|
||||||
|
|
||||||
/* Register builtin methods */
|
/* Register builtin methods */
|
||||||
v8js_register_methods(tpl, c);
|
v8js_register_methods(global_template, c);
|
||||||
|
|
||||||
/* Create context */
|
/* 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) {
|
if (exts) {
|
||||||
v8js_free_ext_strarr(exts, exts_count);
|
v8js_free_ext_strarr(exts, exts_count);
|
||||||
@ -447,6 +447,7 @@ static PHP_METHOD(V8Js, __construct)
|
|||||||
}
|
}
|
||||||
|
|
||||||
context->SetAlignedPointerInEmbedderData(1, c);
|
context->SetAlignedPointerInEmbedderData(1, c);
|
||||||
|
context->Global()->Set(context, V8JS_SYM("global"), context->Global());
|
||||||
c->context.Reset(isolate, context);
|
c->context.Reset(isolate, context);
|
||||||
|
|
||||||
/* Enter context */
|
/* Enter context */
|
||||||
|
Loading…
Reference in New Issue
Block a user