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]));

0 commit comments

Comments
 (0)