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

Commit 39fb2bb

Browse files
committed
Add V8\ScriptCompiler\CompileOptions class
1 parent 41e5853 commit 39fb2bb

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

config.m4

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ if test "$PHP_V8" != "no"; then
169169
src/php_v8_script.cc \
170170
src/php_v8_unbound_script.cc \
171171
src/php_v8_cached_data.cc \
172+
src/php_v8_compile_options.cc \
172173
src/php_v8_data.cc \
173174
src/php_v8_value.cc \
174175
src/php_v8_primitive.cc \

src/php_v8_compile_options.cc

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* This file is part of the pinepain/php-v8 PHP extension.
3+
*
4+
* Copyright (c) 2015-2017 Bogdan Padalko <pinepain@gmail.com>
5+
*
6+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
7+
*
8+
* For the full copyright and license information, please view the
9+
* LICENSE file that was distributed with this source or visit
10+
* http://opensource.org/licenses/MIT
11+
*/
12+
13+
#ifdef HAVE_CONFIG_H
14+
#include "config.h"
15+
#endif
16+
17+
#include "php_v8_compile_options.h"
18+
#include "php_v8.h"
19+
20+
zend_class_entry* php_v8_compile_options_class_entry;
21+
#define this_ce php_v8_compile_options_class_entry
22+
23+
24+
static const zend_function_entry php_v8_compile_options_methods[] = {
25+
PHP_FE_END
26+
};
27+
28+
PHP_MINIT_FUNCTION(php_v8_compile_options) {
29+
zend_class_entry ce;
30+
INIT_NS_CLASS_ENTRY(ce, "V8\\ScriptCompiler", "CompileOptions", php_v8_compile_options_methods);
31+
this_ce = zend_register_internal_class(&ce);
32+
33+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kNoCompileOptions"), v8::ScriptCompiler::CompileOptions::kNoCompileOptions);
34+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kProduceParserCache"), v8::ScriptCompiler::CompileOptions::kProduceParserCache);
35+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kConsumeParserCache"), v8::ScriptCompiler::CompileOptions::kConsumeParserCache);
36+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kProduceCodeCache"), v8::ScriptCompiler::CompileOptions::kProduceCodeCache);
37+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kConsumeCodeCache"), v8::ScriptCompiler::CompileOptions::kConsumeCodeCache);
38+
39+
return SUCCESS;
40+
}

src/php_v8_compile_options.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* This file is part of the pinepain/php-v8 PHP extension.
3+
*
4+
* Copyright (c) 2015-2017 Bogdan Padalko <pinepain@gmail.com>
5+
*
6+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
7+
*
8+
* For the full copyright and license information, please view the
9+
* LICENSE file that was distributed with this source or visit
10+
* http://opensource.org/licenses/MIT
11+
*/
12+
13+
#ifndef PHP_V8_COMPILE_OPTIONS_H
14+
#define PHP_V8_COMPILE_OPTIONS_H
15+
16+
#include "php_v8_exceptions.h"
17+
#include <v8.h>
18+
19+
extern "C" {
20+
#include "php.h"
21+
22+
#ifdef ZTS
23+
#include "TSRM.h"
24+
#endif
25+
}
26+
27+
extern zend_class_entry* php_v8_compile_options_class_entry;
28+
29+
#define PHP_V8_CHECK_COMPILER_OPTIONS_RANGE(options, message) \
30+
if (options < static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kNoCompileOptions) \
31+
|| options > static_cast<zend_long>(v8::ScriptCompiler::CompileOptions::kConsumeCodeCache)) { \
32+
PHP_V8_THROW_VALUE_EXCEPTION(message); \
33+
return; \
34+
}
35+
36+
PHP_MINIT_FUNCTION (php_v8_compile_options);
37+
38+
39+
#endif //PHP_V8_COMPILE_OPTIONS_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
4+
namespace V8\ScriptCompiler;
5+
6+
7+
class CompileOptions
8+
{
9+
const kNoCompileOptions = 0;
10+
const kProduceParserCache = 1;
11+
const kConsumeParserCache = 2;
12+
const kProduceCodeCache = 3;
13+
const kConsumeCodeCache = 4;
14+
}

tests/V8CompileOptions.phpt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
V8\ScriptCompiler\CompileOptions
3+
--SKIPIF--
4+
<?php if (!extension_loaded("v8")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
// Bootstraps:
9+
$obj = new V8\ScriptCompiler\CompileOptions();
10+
11+
// Tests:
12+
13+
/** @var \Phpv8Testsuite $helper */
14+
$helper = require '.testsuite.php';
15+
16+
$helper->header('Object representation');
17+
$helper->dump($obj);
18+
$helper->space();
19+
20+
21+
$helper->header('Class constants');
22+
$helper->dump_object_constants($obj);
23+
$helper->space();
24+
25+
?>
26+
--EXPECT--
27+
Object representation:
28+
----------------------
29+
object(V8\ScriptCompiler\CompileOptions)#1 (0) {
30+
}
31+
32+
33+
Class constants:
34+
----------------
35+
V8\ScriptCompiler\CompileOptions::kNoCompileOptions = 0
36+
V8\ScriptCompiler\CompileOptions::kProduceParserCache = 1
37+
V8\ScriptCompiler\CompileOptions::kConsumeParserCache = 2
38+
V8\ScriptCompiler\CompileOptions::kProduceCodeCache = 3
39+
V8\ScriptCompiler\CompileOptions::kConsumeCodeCache = 4

v8.cc

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "php_v8_script.h"
3434
#include "php_v8_unbound_script.h"
3535
#include "php_v8_cached_data.h"
36+
#include "php_v8_compile_options.h"
3637
#include "php_v8_null.h"
3738
#include "php_v8_boolean.h"
3839
#include "php_v8_symbol.h"
@@ -110,6 +111,7 @@ PHP_MINIT_FUNCTION(v8)
110111
PHP_MINIT(php_v8_script)(INIT_FUNC_ARGS_PASSTHRU);
111112
PHP_MINIT(php_v8_unbound_script)(INIT_FUNC_ARGS_PASSTHRU);
112113
PHP_MINIT(php_v8_cached_data)(INIT_FUNC_ARGS_PASSTHRU);
114+
PHP_MINIT(php_v8_compile_options)(INIT_FUNC_ARGS_PASSTHRU);
113115

114116
PHP_MINIT(php_v8_exception)(INIT_FUNC_ARGS_PASSTHRU);
115117
PHP_MINIT(php_v8_try_catch)(INIT_FUNC_ARGS_PASSTHRU);

0 commit comments

Comments
 (0)