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

Commit c6255d4

Browse files
committedOct 5, 2017
Add support for ScriptCompiler::kProduceFullCodeCache, closes #71
1 parent 2695b51 commit c6255d4

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
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

+4-9
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class Dumper
1313
{
1414
$re = new ReflectionExtension('v8');
1515

16-
echo 'Name: ', $re->getName(), PHP_EOL;
17-
echo 'Version: ', $re->getVersion(), PHP_EOL;
16+
// echo 'Name: ', $re->getName(), PHP_EOL;
17+
// echo 'Version: ', $re->getVersion(), PHP_EOL;
1818

1919
echo PHP_EOL;
2020
echo 'Extension-global functions:', PHP_EOL;
@@ -204,14 +204,8 @@ $d = new Dumper();
204204

205205
$d->dumpExtension();
206206

207-
// EXPECTF: ---/Version: .+/
208-
// EXPECTF: +++Version: %s
209-
210207
?>
211-
--EXPECTF--
212-
Name: v8
213-
Version: %s
214-
208+
--EXPECT--
215209
Extension-global functions:
216210
none
217211

@@ -412,6 +406,7 @@ class V8\ScriptCompiler
412406
const OPTION_PRODUCE_PARSER_CACHE = 1
413407
const OPTION_CONSUME_PARSER_CACHE = 2
414408
const OPTION_PRODUCE_CODE_CACHE = 3
409+
const OPTION_PRODUCE_FULL_CODE_CACHE = 4
415410
const OPTION_CONSUME_CODE_CACHE = 5
416411
public static function cachedDataVersionTag(): int
417412
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)
This repository has been archived.