Skip to content
This repository has been archived by the owner on Mar 29, 2024. It is now read-only.

Commit

Permalink
Add $context parameter to Script::Run() method
Browse files Browse the repository at this point in the history
  • Loading branch information
pinepain committed Jul 19, 2016
1 parent 17f6c56 commit 92ae276
Show file tree
Hide file tree
Showing 44 changed files with 72 additions and 64 deletions.
12 changes: 9 additions & 3 deletions src/php_v8_script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,19 @@ static PHP_METHOD(V8Script, getOrigin)

static PHP_METHOD(V8Script, Run)
{
if (zend_parse_parameters_none() == FAILURE) {
zval *php_v8_context_zv;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_context_zv) == FAILURE) {
return;
}

PHP_V8_FETCH_SCRIPT_WITH_CHECK(getThis(), php_v8_script);
PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context);

PHP_V8_DATA_ISOLATES_CHECK(php_v8_script, php_v8_context);

PHP_V8_ENTER_STORED_ISOLATE(php_v8_script);
PHP_V8_ENTER_STORED_CONTEXT(php_v8_script);
PHP_V8_ENTER_CONTEXT(php_v8_context);

v8::Local<v8::Script> local_script = php_v8_script_get_local(isolate, php_v8_script);

Expand Down Expand Up @@ -230,7 +235,8 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_source_getOrigin, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\ScriptOrigin", 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_source_Run, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\Value", 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_source_Run, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\Value", 1)
ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0)
ZEND_END_ARG_INFO()


Expand Down
6 changes: 4 additions & 2 deletions stubs/src/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ public function getOrigin() : ScriptOrigin
* context in which it was created (ScriptCompiler::CompileBound or
* UnboundScript::BindToCurrentContext()).
*
* @return \V8\Value | \V8\StringValue | \V8\BooleanValue | \V8\NumberValue | \V8\ObjectValue | \V8\FunctionObject
* @param \V8\Context $context
*
* @return BooleanValue|FunctionObject|NumberValue|ObjectValue|StringValue|Value
*/
public function Run() : Value
public function Run(Context $context) : Value
{
}

Expand Down
2 changes: 1 addition & 1 deletion tests/.v8-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function CompileRun(\V8\Context $context, $script) {

$script = new \V8\Script($context, $script, new \V8\ScriptOrigin('test.js'));

return $script->Run();
return $script->Run($context);
}

public function CompileTryRun(\V8\Context $context, $script) {
Expand Down
2 changes: 1 addition & 1 deletion tests/V8ArrayObject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ print("arr.slice(1): ", arr.slice(1), "\n");
$file_name1 = 'test.js';

$script1 = new V8\Script($context, new \V8\StringValue($isolate, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion tests/V8ArrayObject_Length.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $source1 = '
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

echo $res1->Length(), PHP_EOL;

Expand Down
2 changes: 1 addition & 1 deletion tests/V8BooleanObject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ new Boolean(false);
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);
$helper->space();

$v8_helper->run_checks($res1, 'Checkers on boxed from script');
Expand Down
2 changes: 1 addition & 1 deletion tests/V8Context_weakness.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $script1 = new \V8\Script(
);


$obj = $script1->Run()->ToObject($script1->GetContext()); // contest should be stored in object
$obj = $script1->Run($script1->GetContext())->ToObject($script1->GetContext()); // contest should be stored in object

$script1 = null;

Expand Down
6 changes: 3 additions & 3 deletions tests/V8DateObject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ orig
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);
$helper->space();

$helper->header('Returned value should be the same');
Expand Down Expand Up @@ -83,7 +83,7 @@ $file_name1 = 'test.js';


$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);
$helper->value_matches($test_time, $value->ValueOf());
$helper->space();

Expand All @@ -105,7 +105,7 @@ $file_name1 = 'test.js';
// TODO: for some reason v8 still be notified about TZ changes, see https://groups.google.com/forum/?fromgroups#!topic/v8-users/f249jR67ANk
// TODO: we temporary set EDT instead of PDT which was before
$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);
$helper->value_matches($test_time, $value->ValueOf());
$helper->space();

Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionCallbackInfo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

$helper->dump($script1->Run()->ToString($context1)->Value());
$helper->dump($script1->Run($context1)->ToString($context1)->Value());


echo 'We are done for now', PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionObject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

$helper->dump($script1->Run()->ToString($context1)->Value());
$helper->dump($script1->Run($context1)->ToString($context1)->Value());
$helper->line();

$helper->dump_object_methods($func, [], new ArrayMapFilter(['GetScriptOrigin' => true]));
Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionObject_die.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

$res = $script1->Run()->ToString($context1)->Value();
$res = $script1->Run($context1)->ToString($context1)->Value();
$helper->pretty_dump('Script result', $res);

echo 'We are done for now', PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionTemplate_GetFunction.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $file_name1 = 'test.js';

$script1 = new \V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

$helper->dump($script1->Run()->ToString($context1)->Value());
$helper->dump($script1->Run($context1)->ToString($context1)->Value());

echo 'We are done for now', PHP_EOL;

Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionTemplate_SetCallHandler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $file_name1 = 'test.js';
$script1 = new \V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

try {
$helper->dump($script1->Run()->ToString($context1)->Value());
$helper->dump($script1->Run($context1)->ToString($context1)->Value());
} catch (Exception $e) {
$helper->exception_export($e);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionTemplate_exception_in_php.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $file_name1 = 'test.js';
$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

try {
$helper->dump($script1->Run()->ToString($context1)->Value());
$helper->dump($script1->Run($context1)->ToString($context1)->Value());
} catch (Exception $e) {
$helper->exception_export($e);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/V8FunctionTemplate_require_implementation.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ $require_func_tpl_cache = new \V8\FunctionTemplate($isolate1, function (\V8\Func

$script = new \V8\Script($new_context, new \V8\StringValue($isolate, $code[$module]), new \V8\ScriptOrigin($module));

$loaded_cache[$module] = $script->Run();
$loaded_cache[$module] = $script->Run($new_context);
}

$info->GetReturnValue()->Set($loaded_cache[$module]);
Expand All @@ -60,7 +60,7 @@ $file_name2 = 'experiment.js';
$helper->header('Test require() (with cache)');

$script2 = new V8\Script($context, new \V8\StringValue($isolate1, $JS), new \V8\ScriptOrigin($file_name2));
$res2 = $script2->Run();
$res2 = $script2->Run($context);

$helper->space();

Expand All @@ -85,7 +85,7 @@ $require_func_tpl_nocache = new \V8\FunctionTemplate($isolate1, function (\V8\Fu
$loaded_no_cache[$module] = $script;
}

$info->GetReturnValue()->Set($loaded_no_cache[$module]->Run());
$info->GetReturnValue()->Set($loaded_no_cache[$module]->Run($context));
});


Expand All @@ -110,7 +110,7 @@ $file_name2 = 'experiment.js';
$helper->header('Test require() (no cache)');

$script2 = new V8\Script($context, new \V8\StringValue($isolate1, $JS), new \V8\ScriptOrigin($file_name2));
$res2 = $script2->Run();
$res2 = $script2->Run($context);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion tests/V8FunctionTemplate_weakness.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ $file_name1 = 'test.js';
try {
$script1 = new Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

$script1->Run()->Value();
$script1->Run($context1)->Value();
} catch (Exception $e) {
$helper->exception_export($e);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/V8Isolate_limit_memory.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $helper->dump($isolate);
$helper->line();

try {
$res = $script->Run();
$res = $script->Run($context);
} catch(\V8\Exceptions\MemoryLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
Expand Down
4 changes: 2 additions & 2 deletions tests/V8Isolate_limit_memory_nested.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info
$script = new V8\Script($info->GetContext(), new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin('wait_for_termination.js'));

try {
$script->Run();
$script->Run($info->GetContext());
} catch (\V8\Exceptions\MemoryLimitException $e) {
$helper->exception_export($e);
echo 'wait loop terminated', PHP_EOL;
Expand Down Expand Up @@ -77,7 +77,7 @@ $helper->line();

$t = microtime(true);
try {
$script->Run();
$script->Run($context);
} catch(\V8\Exceptions\MemoryLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion tests/V8Isolate_limit_memory_not_hit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $helper->line();

$t = microtime(true);
try {
$script->Run();
$script->Run($context);
} finally {
$helper->line();
$t = microtime(true) - $t;
Expand Down
2 changes: 1 addition & 1 deletion tests/V8Isolate_limit_time.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $helper->line();

$t = microtime(true);
try {
$res = $script->Run();
$res = $script->Run($context);
} catch(\V8\Exceptions\TimeLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
Expand Down
4 changes: 2 additions & 2 deletions tests/V8Isolate_limit_time_nested.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ $func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $inf
$script = new V8\Script($info->GetContext(), new \V8\StringValue($isolate, 'for(;;);'), new \V8\ScriptOrigin('wait_for_termination.js'));

try {
$script->Run();
$script->Run($info->GetContext());
} catch (\V8\Exceptions\TimeLimitException $e) {
$helper->exception_export($e);
echo 'wait loop terminated', PHP_EOL;
Expand Down Expand Up @@ -77,7 +77,7 @@ $helper->line();

$t = microtime(true);
try {
$script1->Run();
$script1->Run($context1);
} catch(\V8\Exceptions\TimeLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
Expand Down
2 changes: 1 addition & 1 deletion tests/V8Isolate_limit_time_not_hit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ $helper->line();

$t = microtime(true);
try {
$script->Run();
$script->Run($context);
} finally {
$helper->line();
$t = microtime(true) - $t;
Expand Down
2 changes: 1 addition & 1 deletion tests/V8Isolate_limit_time_set_during_execution.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ $helper->line();

$t = microtime(true);
try {
$script1->Run();
$script1->Run($context1);
} catch(\V8\Exceptions\TimeLimitException $e) {
$helper->exception_export($e);
echo 'script execution terminated', PHP_EOL;
Expand Down
4 changes: 2 additions & 2 deletions tests/V8Isolate_nested_termination_exceptions.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $inf
$isolate->TerminateExecution();

try {
$script->Run();
$script->Run($info->GetContext());
} catch (\V8\Exceptions\TerminationException $e) {
echo 'wait loop terminated', PHP_EOL;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ $file_name1 = 'test.js';
$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

try {
$script1->Run();
$script1->Run($context1);
} catch (\V8\Exceptions\TerminationException $e) {
echo 'script execution terminated', PHP_EOL;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/V8NumberObject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ val';
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);
$helper->space();

$helper->header('Returned value should be the same');
Expand All @@ -60,7 +60,7 @@ $source1 = 'new Number(11.22);';
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

$v8_helper->run_checks($res1, 'Checkers on boxed from script');

Expand Down
2 changes: 1 addition & 1 deletion tests/V8ObjectTemplate_MarkAsUndetectable.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ print("!test2: ", !test2, "\n");
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion tests/V8ObjectTemplate_SetCallAsFunctionHandler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ try {
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion tests/V8ObjectTemplate_SetHandlerForIndexedProperty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ for (i in test) {
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ for (i in test) {
$file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

?>
--EXPECT--
Expand Down
4 changes: 2 additions & 2 deletions tests/V8ObjectTemplate_SetHandler_both.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ $allow_named = true;
$allow_indexed = false;

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);
$helper->space();


Expand Down Expand Up @@ -173,7 +173,7 @@ $allow_named = false;
$allow_indexed = true;

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
$res1 = $script1->Run();
$res1 = $script1->Run($context1);

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion tests/V8ObjectValue_SetAccessor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ $file_name1 = 'test.js';

$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));

$helper->dump($script1->Run()->ToString($context1)->Value());
$helper->dump($script1->Run($context1)->ToString($context1)->Value());

?>
--EXPECT--
Expand Down
Loading

0 comments on commit 92ae276

Please sign in to comment.