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

Commit 260773e

Browse files
committed
Add V8\ObjectValue::SetIntegrityLevel()
V8 commit: v8/v8@93c60dc
1 parent fcc9eb1 commit 260773e

15 files changed

+343
-19
lines changed

config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ if test "$PHP_V8" != "no"; then
209209
src/php_v8_integer.cc \
210210
src/php_v8_int32.cc \
211211
src/php_v8_uint32.cc \
212+
src/php_v8_integrity_level.cc \
212213
src/php_v8_object.cc \
213214
src/php_v8_function.cc \
214215
src/php_v8_array.cc \

scripts/replace_expect.php

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
$tests_dir = realpath(__DIR__ . '/../tests');

src/php_v8_integrity_level.cc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| This file is part of the pinepain/php-v8 PHP extension. |
4+
| |
5+
| Copyright (c) 2015-2016 Bogdan Padalko <pinepain@gmail.com> |
6+
| |
7+
| Licensed under the MIT license: http://opensource.org/licenses/MIT |
8+
| |
9+
| For the full copyright and license information, please view the |
10+
| LICENSE file that was distributed with this source or visit |
11+
| http://opensource.org/licenses/MIT |
12+
+----------------------------------------------------------------------+
13+
*/
14+
15+
#ifdef HAVE_CONFIG_H
16+
#include "config.h"
17+
#endif
18+
19+
#include "php_v8_integrity_level.h"
20+
#include "php_v8.h"
21+
22+
zend_class_entry* php_v8_integrity_level_class_entry;
23+
#define this_ce php_v8_integrity_level_class_entry
24+
25+
26+
static const zend_function_entry php_v8_integrity_level_methods[] = {
27+
PHP_FE_END
28+
};
29+
30+
31+
PHP_MINIT_FUNCTION(php_v8_integrity_level) {
32+
zend_class_entry ce;
33+
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "IntegrityLevel", php_v8_integrity_level_methods);
34+
this_ce = zend_register_internal_class(&ce);
35+
36+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kFrozen"), static_cast<zend_long>(v8::IntegrityLevel::kFrozen));
37+
zend_declare_class_constant_long(this_ce, ZEND_STRL("kSealed"), static_cast<zend_long>(v8::IntegrityLevel::kSealed));
38+
39+
return SUCCESS;
40+
}
41+
42+
43+
/*
44+
* Local variables:
45+
* tab-width: 4
46+
* c-basic-offset: 4
47+
* End:
48+
* vim600: noet sw=4 ts=4 fdm=marker
49+
* vim<600: noet sw=4 ts=4
50+
*/

src/php_v8_integrity_level.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
+----------------------------------------------------------------------+
3+
| This file is part of the pinepain/php-v8 PHP extension. |
4+
| |
5+
| Copyright (c) 2015-2016 Bogdan Padalko <pinepain@gmail.com> |
6+
| |
7+
| Licensed under the MIT license: http://opensource.org/licenses/MIT |
8+
| |
9+
| For the full copyright and license information, please view the |
10+
| LICENSE file that was distributed with this source or visit |
11+
| http://opensource.org/licenses/MIT |
12+
+----------------------------------------------------------------------+
13+
*/
14+
15+
#ifndef PHP_V8_INTEGRITY_LEVEL_H
16+
#define PHP_V8_INTEGRITY_LEVEL_H
17+
18+
#include <v8.h>
19+
20+
extern "C" {
21+
#include "php.h"
22+
23+
#ifdef ZTS
24+
#include "TSRM.h"
25+
#endif
26+
}
27+
28+
extern zend_class_entry* php_v8_integrity_level_class_entry;
29+
30+
PHP_MINIT_FUNCTION (php_v8_integrity_level);
31+
32+
#define PHP_V8_INTEGRITY_LEVEL_FLAGS ( 0 \
33+
| static_cast<long>(v8::IntegrityLevel::kFrozen) \
34+
| static_cast<long>(v8::IntegrityLevel::kSealed) \
35+
)
36+
37+
38+
#endif //PHP_V8_INTEGRITY_LEVEL_H
39+
/*
40+
* Local variables:
41+
* tab-width: 4
42+
* c-basic-offset: 4
43+
* End:
44+
* vim600: noet sw=4 ts=4 fdm=marker
45+
* vim<600: noet sw=4 ts=4
46+
*/
47+
48+
49+
50+
51+

src/php_v8_object.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endif
1818

1919
#include "php_v8_object.h"
20+
#include "php_v8_integrity_level.h"
2021
#include "php_v8_exceptions.h"
2122
#include "php_v8_function_template.h"
2223
#include "php_v8_function.h"
@@ -933,6 +934,40 @@ static PHP_METHOD(V8Object, GetConstructorName) {
933934
php_v8_get_or_create_value(return_value, local_object->GetConstructorName(), isolate);
934935
}
935936

937+
static PHP_METHOD(V8Object, SetIntegrityLevel) {
938+
zval *php_v8_context_zv;
939+
zend_long level;
940+
941+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ol", &php_v8_context_zv, &level) == FAILURE) {
942+
return;
943+
}
944+
945+
PHP_V8_VALUE_FETCH_WITH_CHECK(getThis(), php_v8_value);
946+
PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context);
947+
948+
PHP_V8_DATA_ISOLATES_CHECK(php_v8_value, php_v8_context)
949+
950+
PHP_V8_ENTER_STORED_ISOLATE(php_v8_value);
951+
PHP_V8_ENTER_CONTEXT(php_v8_context);
952+
953+
v8::Local<v8::Context> local_context = php_v8_context_get_local(isolate, php_v8_context);
954+
v8::Local<v8::Object> local_obj = php_v8_value_get_object_local(isolate, php_v8_value);
955+
956+
level = level ? level & PHP_V8_INTEGRITY_LEVEL_FLAGS : level;
957+
958+
PHP_V8_TRY_CATCH(isolate);
959+
PHP_V8_INIT_ISOLATE_LIMITS_ON_OBJECT_VALUE(php_v8_value);
960+
961+
v8::Maybe<bool> maybe_res = local_obj->SetIntegrityLevel(local_context, static_cast<v8::IntegrityLevel>(level));
962+
963+
PHP_V8_MAYBE_CATCH(php_v8_context, try_catch);
964+
PHP_V8_THROW_EXCEPTION_WHEN_NOTHING(maybe_res, "Failed to set integrity level");
965+
966+
RETURN_BOOL(maybe_res.FromJust());
967+
}
968+
969+
970+
936971
static PHP_METHOD(V8Object, HasOwnProperty) {
937972
zval *php_v8_context_zv;
938973
zval *php_v8_name_zv;
@@ -1525,6 +1560,11 @@ ZEND_END_ARG_INFO()
15251560
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_object_GetConstructorName, ZEND_RETURN_VALUE, 0, IS_OBJECT, PHP_V8_NS "\\StringValue", 0)
15261561
ZEND_END_ARG_INFO()
15271562

1563+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_object_SetIntegrityLevel, ZEND_RETURN_VALUE, 2, _IS_BOOL, NULL, 0)
1564+
ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0)
1565+
ZEND_ARG_TYPE_INFO(0, level, IS_LONG, 0)
1566+
ZEND_END_ARG_INFO()
1567+
15281568
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_v8_object_HasOwnProperty, ZEND_RETURN_VALUE, 2, _IS_BOOL, NULL, 0)
15291569
ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0)
15301570
ZEND_ARG_INFO(0, key)
@@ -1630,6 +1670,7 @@ static const zend_function_entry php_v8_object_methods[] = {
16301670
PHP_ME(V8Object, FindInstanceInPrototypeChain, arginfo_php_v8_object_FindInstanceInPrototypeChain, ZEND_ACC_PUBLIC)
16311671
PHP_ME(V8Object, ObjectProtoToString, arginfo_php_v8_object_ObjectProtoToString, ZEND_ACC_PUBLIC)
16321672
PHP_ME(V8Object, GetConstructorName, arginfo_v8_object_GetConstructorName, ZEND_ACC_PUBLIC)
1673+
PHP_ME(V8Object, SetIntegrityLevel, arginfo_v8_object_SetIntegrityLevel, ZEND_ACC_PUBLIC)
16331674

16341675
PHP_ME(V8Object, HasOwnProperty, arginfo_v8_object_HasOwnProperty, ZEND_ACC_PUBLIC)
16351676
PHP_ME(V8Object, HasRealNamedProperty, arginfo_v8_object_HasRealNamedProperty, ZEND_ACC_PUBLIC)

stubs/src/IntegrityLevel.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
+----------------------------------------------------------------------+
5+
| This file is part of the pinepain/php-v8 PHP extension. |
6+
| |
7+
| Copyright (c) 2015-2016 Bogdan Padalko <pinepain@gmail.com> |
8+
| |
9+
| Licensed under the MIT license: http://opensource.org/licenses/MIT |
10+
| |
11+
| For the full copyright and license information, please view the |
12+
| LICENSE file that was distributed with this source or visit |
13+
| http://opensource.org/licenses/MIT |
14+
+----------------------------------------------------------------------+
15+
*/
16+
17+
18+
namespace V8;
19+
20+
/**
21+
* Integrity level for objects.
22+
*/
23+
class IntegrityLevel
24+
{
25+
const kFrozen = 0;
26+
const kSealed = 1;
27+
}

stubs/src/ObjectValue.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ public function CreateDataPropertyIndex(Context $context, int $index, Value $val
103103
*
104104
* @return bool
105105
*/
106-
public function DefineOwnProperty(Context $context, NameValue $key, Value $value, int $attributes = PropertyAttribute::None) : bool
106+
public function DefineOwnProperty(
107+
Context $context,
108+
NameValue $key,
109+
Value $value,
110+
int $attributes = PropertyAttribute::None
111+
) : bool
107112
{
108113
}
109114

@@ -319,6 +324,18 @@ public function GetConstructorName() : StringValue
319324
{
320325
}
321326

327+
/**
328+
* Sets the integrity level of the object.
329+
*
330+
* @param Context $context
331+
* @param int $level One of \V8\IntegrityLevel::{kFrozen, kSealed}
332+
*
333+
* @return bool
334+
*/
335+
public function SetIntegrityLevel(Context $context, int $level) : bool
336+
{
337+
}
338+
322339
/**
323340
* @param Context $context
324341
* @param string $key

tests/V8ArrayObject.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ V8\ArrayObject::CreationContext() matches expected value
129129
Converters:
130130
-----------
131131
V8\ArrayObject(V8\Value)->ToBoolean():
132-
object(V8\BooleanValue)#95 (1) {
132+
object(V8\BooleanValue)#96 (1) {
133133
["isolate":"V8\Value":private]=>
134134
object(V8\Isolate)#3 (5) {
135135
["snapshot":"V8\Isolate":private]=>
@@ -145,7 +145,7 @@ V8\ArrayObject(V8\Value)->ToBoolean():
145145
}
146146
}
147147
V8\ArrayObject(V8\Value)->ToNumber():
148-
object(V8\NumberValue)#95 (1) {
148+
object(V8\NumberValue)#96 (1) {
149149
["isolate":"V8\Value":private]=>
150150
object(V8\Isolate)#3 (5) {
151151
["snapshot":"V8\Isolate":private]=>
@@ -161,7 +161,7 @@ V8\ArrayObject(V8\Value)->ToNumber():
161161
}
162162
}
163163
V8\ArrayObject(V8\Value)->ToString():
164-
object(V8\StringValue)#95 (1) {
164+
object(V8\StringValue)#96 (1) {
165165
["isolate":"V8\Value":private]=>
166166
object(V8\Isolate)#3 (5) {
167167
["snapshot":"V8\Isolate":private]=>
@@ -177,7 +177,7 @@ V8\ArrayObject(V8\Value)->ToString():
177177
}
178178
}
179179
V8\ArrayObject(V8\Value)->ToDetailString():
180-
object(V8\StringValue)#95 (1) {
180+
object(V8\StringValue)#96 (1) {
181181
["isolate":"V8\Value":private]=>
182182
object(V8\Isolate)#3 (5) {
183183
["snapshot":"V8\Isolate":private]=>
@@ -246,7 +246,7 @@ V8\ArrayObject(V8\Value)->ToObject():
246246
}
247247
}
248248
V8\ArrayObject(V8\Value)->ToInteger():
249-
object(V8\NumberValue)#95 (1) {
249+
object(V8\NumberValue)#96 (1) {
250250
["isolate":"V8\Value":private]=>
251251
object(V8\Isolate)#3 (5) {
252252
["snapshot":"V8\Isolate":private]=>
@@ -262,7 +262,7 @@ V8\ArrayObject(V8\Value)->ToInteger():
262262
}
263263
}
264264
V8\ArrayObject(V8\Value)->ToUint32():
265-
object(V8\NumberValue)#95 (1) {
265+
object(V8\NumberValue)#96 (1) {
266266
["isolate":"V8\Value":private]=>
267267
object(V8\Isolate)#3 (5) {
268268
["snapshot":"V8\Isolate":private]=>
@@ -278,7 +278,7 @@ V8\ArrayObject(V8\Value)->ToUint32():
278278
}
279279
}
280280
V8\ArrayObject(V8\Value)->ToInt32():
281-
object(V8\NumberValue)#95 (1) {
281+
object(V8\NumberValue)#96 (1) {
282282
["isolate":"V8\Value":private]=>
283283
object(V8\Isolate)#3 (5) {
284284
["snapshot":"V8\Isolate":private]=>

tests/V8FunctionObject.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,15 @@ Should output Hello World string
149149
string(11) "Script done"
150150

151151
v8Tests\TrackingDtors\FunctionObject(V8\FunctionObject)->GetScriptOrigin():
152-
object(V8\ScriptOrigin)#110 (6) {
152+
object(V8\ScriptOrigin)#111 (6) {
153153
["resource_name":"V8\ScriptOrigin":private]=>
154154
string(0) ""
155155
["resource_line_offset":"V8\ScriptOrigin":private]=>
156156
int(0)
157157
["resource_column_offset":"V8\ScriptOrigin":private]=>
158158
int(0)
159159
["options":"V8\ScriptOrigin":private]=>
160-
object(V8\ScriptOriginOptions)#111 (3) {
160+
object(V8\ScriptOriginOptions)#112 (3) {
161161
["is_embedder_debug_script":"V8\ScriptOriginOptions":private]=>
162162
bool(false)
163163
["is_shared_cross_origin":"V8\ScriptOriginOptions":private]=>

tests/V8IntegrityLevel.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
V8\PropertyAttribute
3+
--SKIPIF--
4+
<?php if (!extension_loaded("v8")) print "skip"; ?>
5+
--FILE--
6+
<?php
7+
8+
// Bootstraps:
9+
$obj = new V8\IntegrityLevel();
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\IntegrityLevel)#1 (0) {
30+
}
31+
32+
33+
Class constants:
34+
----------------
35+
V8\IntegrityLevel::kFrozen = 0
36+
V8\IntegrityLevel::kSealed = 1

0 commit comments

Comments
 (0)