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

Commit 28a3b03

Browse files
committed
Add support for ScriptCompiler::kProduceFullCodeCache, closes #71
1 parent 2695b51 commit 28a3b03

File tree

4 files changed

+51
-5
lines changed

4 files changed

+51
-5
lines changed

src/php_v8_script_compiler.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,12 @@ PHP_MINIT_FUNCTION(php_v8_script_compiler)
292292
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "ScriptCompiler", php_v8_script_compiler_methods);
293293
this_ce = zend_register_internal_class(&ce);
294294

295-
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_NO_COMPILE_OPTIONS"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kNoCompileOptions));
296-
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_PRODUCE_PARSER_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kProduceParserCache));
297-
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_CONSUME_PARSER_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kConsumeParserCache));
298-
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_PRODUCE_CODE_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kProduceCodeCache));
299-
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_CONSUME_CODE_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache));
295+
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_NO_COMPILE_OPTIONS"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kNoCompileOptions));
296+
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_PRODUCE_PARSER_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kProduceParserCache));
297+
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_CONSUME_PARSER_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kConsumeParserCache));
298+
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_PRODUCE_CODE_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kProduceCodeCache));
299+
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_PRODUCE_FULL_CODE_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kProduceFullCodeCache));
300+
zend_declare_class_constant_long(this_ce, ZEND_STRL("OPTION_CONSUME_CODE_CACHE"), static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache));
300301

301302
return SUCCESS;
302303
}

stubs/src/ScriptCompiler.php

+7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
*/
1313
class ScriptCompiler
1414
{
15+
const OPTION_NO_COMPILE_OPTIONS = 0;
16+
const OPTION_PRODUCE_PARSER_CACHE = 1;
17+
const OPTION_CONSUME_PARSER_CACHE = 2;
18+
const OPTION_PRODUCE_CODE_CACHE = 3;
19+
const OPTION_PRODUCE_FULL_CODE_CACHE = 4;
20+
const OPTION_CONSUME_CODE_CACHE = 5;
21+
1522
private function __construct()
1623
{
1724
}

tests/001-verify_extension_entities.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ class V8\ScriptCompiler
412412
const OPTION_PRODUCE_PARSER_CACHE = 1
413413
const OPTION_CONSUME_PARSER_CACHE = 2
414414
const OPTION_PRODUCE_CODE_CACHE = 3
415+
const OPTION_PRODUCE_FULL_CODE_CACHE = 4
415416
const OPTION_CONSUME_CODE_CACHE = 5
416417
public static function cachedDataVersionTag(): int
417418
public static function compileUnboundScript(V8\Context $context, V8\ScriptCompiler\Source $source, int $options): V8\UnboundScript

tests/ScriptCompiler_compile.phpt

+37
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,31 @@ $cache_data = null;
104104
$helper->line();
105105
}
106106

107+
{
108+
$helper->header('Test generating full code cache');
109+
$source_string = new V8\StringValue($isolate, '"test " + status');
110+
$source = new \V8\ScriptCompiler\Source($source_string);
111+
$helper->assert('Source cache data is NULL', $source->getCachedData() === null);
112+
$script = V8\ScriptCompiler::compile($context, $source, V8\ScriptCompiler::OPTION_PRODUCE_FULL_CODE_CACHE);
113+
$helper->assert('Source cache data is update', $source->getCachedData() != null);
114+
$helper->assert('Source cache data is not rejected', $source->getCachedData()->isRejected() === false);
115+
116+
$cache_data = $source->getCachedData();
117+
$helper->line();
118+
}
119+
120+
{
121+
$helper->header('Test consuming full code cache');
122+
123+
$source = new \V8\ScriptCompiler\Source($source_string, null, $cache_data);
124+
$helper->assert('Source cache data is set', $source->getCachedData() != null);
125+
$script = V8\ScriptCompiler::compile($context, $source, V8\ScriptCompiler::OPTION_CONSUME_CODE_CACHE);
126+
$helper->assert('Source cache data is still set', $source->getCachedData() != null);
127+
$helper->assert('Source cache data is not rejected', $source->getCachedData()->isRejected() === false);
128+
129+
$helper->line();
130+
}
131+
107132
{
108133
$helper->header('Test consuming code cache for wrong source');
109134
$source_string = new V8\StringValue($isolate, '"other " + status');
@@ -292,6 +317,18 @@ Source cache data is set: ok
292317
Source cache data is still set: ok
293318
Source cache data is not rejected: ok
294319

320+
Test generating full code cache:
321+
--------------------------------
322+
Source cache data is NULL: ok
323+
Source cache data is update: ok
324+
Source cache data is not rejected: ok
325+
326+
Test consuming full code cache:
327+
-------------------------------
328+
Source cache data is set: ok
329+
Source cache data is still set: ok
330+
Source cache data is not rejected: ok
331+
295332
Test consuming code cache for wrong source:
296333
-------------------------------------------
297334
Source cache data is set: ok

0 commit comments

Comments
 (0)