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

Commit 92ae276

Browse files
committed
Add $context parameter to Script::Run() method
1 parent 17f6c56 commit 92ae276

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+72
-64
lines changed

src/php_v8_script.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,19 @@ static PHP_METHOD(V8Script, getOrigin)
187187

188188
static PHP_METHOD(V8Script, Run)
189189
{
190-
if (zend_parse_parameters_none() == FAILURE) {
190+
zval *php_v8_context_zv;
191+
192+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_context_zv) == FAILURE) {
191193
return;
192194
}
193195

194196
PHP_V8_FETCH_SCRIPT_WITH_CHECK(getThis(), php_v8_script);
197+
PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context);
198+
199+
PHP_V8_DATA_ISOLATES_CHECK(php_v8_script, php_v8_context);
195200

196201
PHP_V8_ENTER_STORED_ISOLATE(php_v8_script);
197-
PHP_V8_ENTER_STORED_CONTEXT(php_v8_script);
202+
PHP_V8_ENTER_CONTEXT(php_v8_context);
198203

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

@@ -230,7 +235,8 @@ ZEND_END_ARG_INFO()
230235
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_source_getOrigin, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\ScriptOrigin", 0)
231236
ZEND_END_ARG_INFO()
232237

233-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_source_Run, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\Value", 0)
238+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_source_Run, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\Value", 1)
239+
ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0)
234240
ZEND_END_ARG_INFO()
235241

236242

stubs/src/Script.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ public function getOrigin() : ScriptOrigin
7171
* context in which it was created (ScriptCompiler::CompileBound or
7272
* UnboundScript::BindToCurrentContext()).
7373
*
74-
* @return \V8\Value | \V8\StringValue | \V8\BooleanValue | \V8\NumberValue | \V8\ObjectValue | \V8\FunctionObject
74+
* @param \V8\Context $context
75+
*
76+
* @return BooleanValue|FunctionObject|NumberValue|ObjectValue|StringValue|Value
7577
*/
76-
public function Run() : Value
78+
public function Run(Context $context) : Value
7779
{
7880
}
7981

tests/.v8-helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function CompileRun(\V8\Context $context, $script) {
118118

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

121-
return $script->Run();
121+
return $script->Run($context);
122122
}
123123

124124
public function CompileTryRun(\V8\Context $context, $script) {

tests/V8ArrayObject.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ print("arr.slice(1): ", arr.slice(1), "\n");
5757
$file_name1 = 'test.js';
5858

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

6262
?>
6363
--EXPECT--

tests/V8ArrayObject_Length.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $source1 = '
2020
$file_name1 = 'test.js';
2121

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

2525
echo $res1->Length(), PHP_EOL;
2626

tests/V8BooleanObject.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ new Boolean(false);
4949
$file_name1 = 'test.js';
5050

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

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

tests/V8Context_weakness.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $script1 = new \V8\Script(
3131
);
3232

3333

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

3636
$script1 = null;
3737

tests/V8DateObject.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ orig
5555
$file_name1 = 'test.js';
5656

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

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

8484

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

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

tests/V8FunctionCallbackInfo.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $file_name1 = 'test.js';
4949

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

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

5454

5555
echo 'We are done for now', PHP_EOL;

tests/V8FunctionObject.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $file_name1 = 'test.js';
4242

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

45-
$helper->dump($script1->Run()->ToString($context1)->Value());
45+
$helper->dump($script1->Run($context1)->ToString($context1)->Value());
4646
$helper->line();
4747

4848
$helper->dump_object_methods($func, [], new ArrayMapFilter(['GetScriptOrigin' => true]));

tests/V8FunctionObject_die.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $file_name1 = 'test.js';
3434

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

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

4040
echo 'We are done for now', PHP_EOL;

tests/V8FunctionTemplate_GetFunction.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ $file_name1 = 'test.js';
5151

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

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

5656
echo 'We are done for now', PHP_EOL;
5757

tests/V8FunctionTemplate_SetCallHandler.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $file_name1 = 'test.js';
4343
$script1 = new \V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
4444

4545
try {
46-
$helper->dump($script1->Run()->ToString($context1)->Value());
46+
$helper->dump($script1->Run($context1)->ToString($context1)->Value());
4747
} catch (Exception $e) {
4848
$helper->exception_export($e);
4949
}

tests/V8FunctionTemplate_exception_in_php.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ $file_name1 = 'test.js';
2929
$script1 = new V8\Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
3030

3131
try {
32-
$helper->dump($script1->Run()->ToString($context1)->Value());
32+
$helper->dump($script1->Run($context1)->ToString($context1)->Value());
3333
} catch (Exception $e) {
3434
$helper->exception_export($e);
3535
}

tests/V8FunctionTemplate_require_implementation.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ $require_func_tpl_cache = new \V8\FunctionTemplate($isolate1, function (\V8\Func
3434

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

37-
$loaded_cache[$module] = $script->Run();
37+
$loaded_cache[$module] = $script->Run($new_context);
3838
}
3939

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

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

6565
$helper->space();
6666

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

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

9191

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

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

115115
?>
116116
--EXPECT--

tests/V8FunctionTemplate_weakness.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $file_name1 = 'test.js';
8181
try {
8282
$script1 = new Script($context1, new \V8\StringValue($isolate1, $source1), new \V8\ScriptOrigin($file_name1));
8383

84-
$script1->Run()->Value();
84+
$script1->Run($context1)->Value();
8585
} catch (Exception $e) {
8686
$helper->exception_export($e);
8787
}

tests/V8Isolate_limit_memory.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $helper->dump($isolate);
4343
$helper->line();
4444

4545
try {
46-
$res = $script->Run();
46+
$res = $script->Run($context);
4747
} catch(\V8\Exceptions\MemoryLimitException $e) {
4848
$helper->exception_export($e);
4949
echo 'script execution terminated', PHP_EOL;

tests/V8Isolate_limit_memory_nested.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $func = new V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info
3838
$script = new V8\Script($info->GetContext(), new \V8\StringValue($isolate, $source), new \V8\ScriptOrigin('wait_for_termination.js'));
3939

4040
try {
41-
$script->Run();
41+
$script->Run($info->GetContext());
4242
} catch (\V8\Exceptions\MemoryLimitException $e) {
4343
$helper->exception_export($e);
4444
echo 'wait loop terminated', PHP_EOL;
@@ -77,7 +77,7 @@ $helper->line();
7777

7878
$t = microtime(true);
7979
try {
80-
$script->Run();
80+
$script->Run($context);
8181
} catch(\V8\Exceptions\MemoryLimitException $e) {
8282
$helper->exception_export($e);
8383
echo 'script execution terminated', PHP_EOL;

tests/V8Isolate_limit_memory_not_hit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $helper->line();
3838

3939
$t = microtime(true);
4040
try {
41-
$script->Run();
41+
$script->Run($context);
4242
} finally {
4343
$helper->line();
4444
$t = microtime(true) - $t;

tests/V8Isolate_limit_time.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $helper->line();
4949

5050
$t = microtime(true);
5151
try {
52-
$res = $script->Run();
52+
$res = $script->Run($context);
5353
} catch(\V8\Exceptions\TimeLimitException $e) {
5454
$helper->exception_export($e);
5555
echo 'script execution terminated', PHP_EOL;

tests/V8Isolate_limit_time_nested.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ $func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $inf
2424
$script = new V8\Script($info->GetContext(), new \V8\StringValue($isolate, 'for(;;);'), new \V8\ScriptOrigin('wait_for_termination.js'));
2525

2626
try {
27-
$script->Run();
27+
$script->Run($info->GetContext());
2828
} catch (\V8\Exceptions\TimeLimitException $e) {
2929
$helper->exception_export($e);
3030
echo 'wait loop terminated', PHP_EOL;
@@ -77,7 +77,7 @@ $helper->line();
7777

7878
$t = microtime(true);
7979
try {
80-
$script1->Run();
80+
$script1->Run($context1);
8181
} catch(\V8\Exceptions\TimeLimitException $e) {
8282
$helper->exception_export($e);
8383
echo 'script execution terminated', PHP_EOL;

tests/V8Isolate_limit_time_not_hit.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $helper->line();
3838

3939
$t = microtime(true);
4040
try {
41-
$script->Run();
41+
$script->Run($context);
4242
} finally {
4343
$helper->line();
4444
$t = microtime(true) - $t;

tests/V8Isolate_limit_time_set_during_execution.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $helper->line();
5252

5353
$t = microtime(true);
5454
try {
55-
$script1->Run();
55+
$script1->Run($context1);
5656
} catch(\V8\Exceptions\TimeLimitException $e) {
5757
$helper->exception_export($e);
5858
echo 'script execution terminated', PHP_EOL;

tests/V8Isolate_nested_termination_exceptions.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $func = new V8\FunctionObject($context1, function (\V8\FunctionCallbackInfo $inf
2525
$isolate->TerminateExecution();
2626

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

5757
try {
58-
$script1->Run();
58+
$script1->Run($context1);
5959
} catch (\V8\Exceptions\TerminationException $e) {
6060
echo 'script execution terminated', PHP_EOL;
6161
}

tests/V8NumberObject.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ val';
4949
$file_name1 = 'test.js';
5050

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

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

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

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

tests/V8ObjectTemplate_MarkAsUndetectable.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ print("!test2: ", !test2, "\n");
4141
$file_name1 = 'test.js';
4242

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

4646
?>
4747
--EXPECT--

tests/V8ObjectTemplate_SetCallAsFunctionHandler.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ try {
6565
$file_name1 = 'test.js';
6666

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

7070
?>
7171
--EXPECT--

tests/V8ObjectTemplate_SetHandlerForIndexedProperty.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ for (i in test) {
101101
$file_name1 = 'test.js';
102102

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

106106
?>
107107
--EXPECT--

tests/V8ObjectTemplate_SetHandlerForNamedProperty.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ for (i in test) {
8585
$file_name1 = 'test.js';
8686

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

9090
?>
9191
--EXPECT--

tests/V8ObjectTemplate_SetHandler_both.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ $allow_named = true;
145145
$allow_indexed = false;
146146

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

151151

@@ -173,7 +173,7 @@ $allow_named = false;
173173
$allow_indexed = true;
174174

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

178178
?>
179179
--EXPECT--

tests/V8ObjectValue_SetAccessor.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ $file_name1 = 'test.js';
7676

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

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

8181
?>
8282
--EXPECT--

0 commit comments

Comments
 (0)