mirror of
https://github.com/phpv8/v8js.git
synced 2025-03-11 22:18:44 +00:00
Fix handling of failed context creation, closes #136
This commit is contained in:
parent
4d17ba2566
commit
e67f1f4c9c
25
tests/extensions_error.phpt
Normal file
25
tests/extensions_error.phpt
Normal file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
Test V8::registerExtension() : Register extension with errors
|
||||
--SKIPIF--
|
||||
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
$handlebarsJs = "var root = typeof global !== 'undefined' ? global : window, \$Handlebars = 'test';";
|
||||
echo "-- registerExtension --\n";
|
||||
V8Js::registerExtension('handlebars', $handlebarsJs, [], true);
|
||||
echo "-- creating V8Js object --\n";
|
||||
$v8 = new V8Js();
|
||||
var_dump($v8);
|
||||
?>
|
||||
===EOF===
|
||||
--EXPECTF--
|
||||
-- registerExtension --
|
||||
-- creating V8Js object --
|
||||
Exception thrown during bootstrapping
|
||||
Extension or internal compilation error in handlebars at line 1.
|
||||
Error installing extension 'handlebars'.
|
||||
|
||||
Warning: V8Js::__construct(): Failed to create V8 context. Check that registered extensions do not have errors. in %s on line %d
|
||||
NULL
|
||||
===EOF===
|
@ -352,20 +352,21 @@ static PHP_METHOD(V8Js, __construct)
|
||||
|
||||
/* Create context */
|
||||
v8::Local<v8::Context> context = v8::Context::New(isolate, &extension_conf, tpl->InstanceTemplate());
|
||||
context->SetAlignedPointerInEmbedderData(1, c);
|
||||
c->context.Reset(isolate, context);
|
||||
|
||||
if (exts) {
|
||||
v8js_free_ext_strarr(exts, exts_count);
|
||||
}
|
||||
|
||||
/* If extensions have errors, context will be empty. (NOTE: This is V8 stuff, they expect the passed sources to compile :) */
|
||||
if (c->context.IsEmpty()) {
|
||||
if (context.IsEmpty()) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to create V8 context. Check that registered extensions do not have errors.");
|
||||
ZVAL_NULL(getThis());
|
||||
return;
|
||||
}
|
||||
|
||||
context->SetAlignedPointerInEmbedderData(1, c);
|
||||
c->context.Reset(isolate, context);
|
||||
|
||||
/* Enter context */
|
||||
v8::Context::Scope context_scope(context);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user