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

Commit 7407477

Browse files
committed
Introduce V8\Undefined value and make conatiner classes abstract
1 parent b344971 commit 7407477

31 files changed

+418
-773
lines changed

config.m4

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ if test "$PHP_V8" != "no"; then
175175
src/php_v8_data.cc \
176176
src/php_v8_value.cc \
177177
src/php_v8_primitive.cc \
178+
src/php_v8_undefined.cc \
178179
src/php_v8_null.cc \
179180
src/php_v8_boolean.cc \
180181
src/php_v8_name.cc \

src/php_v8_name.cc

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ PHP_MINIT_FUNCTION(php_v8_name)
5858
zend_class_entry ce;
5959
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "NameValue", php_v8_name_methods);
6060
this_ce = zend_register_internal_class_ex(&ce, php_v8_primitive_class_entry);
61+
this_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
6162

6263
return SUCCESS;
6364
}

src/php_v8_primitive.cc

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ PHP_MINIT_FUNCTION(php_v8_primitive)
3232
zend_class_entry ce;
3333
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PrimitiveValue", php_v8_primitive_methods);
3434
this_ce = zend_register_internal_class_ex(&ce, php_v8_value_class_entry);
35+
this_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
3536

3637
return SUCCESS;
3738
}

src/php_v8_undefined.cc

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This file is part of the pinepain/php-v8 PHP extension.
3+
*
4+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
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_undefined.h"
18+
#include "php_v8_primitive.h"
19+
#include "php_v8_value.h"
20+
#include "php_v8.h"
21+
22+
zend_class_entry *php_v8_undefined_class_entry;
23+
#define this_ce php_v8_undefined_class_entry
24+
25+
26+
static PHP_METHOD(V8Undefined, __construct) {
27+
zval *php_v8_isolate_zv;
28+
29+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) {
30+
return;
31+
}
32+
33+
PHP_V8_VALUE_CONSTRUCT(getThis(), php_v8_isolate_zv, php_v8_isolate, php_v8_value);
34+
35+
php_v8_value->persistent->Reset(isolate, v8::Undefined(isolate));
36+
}
37+
38+
39+
ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_undefined___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1)
40+
ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0)
41+
ZEND_END_ARG_INFO()
42+
43+
44+
static const zend_function_entry php_v8_undefined_methods[] = {
45+
PHP_ME(V8Undefined, __construct, arginfo_v8_undefined___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
46+
PHP_FE_END
47+
};
48+
49+
50+
PHP_MINIT_FUNCTION(php_v8_undefined) {
51+
zend_class_entry ce;
52+
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "UndefinedValue", php_v8_undefined_methods);
53+
this_ce = zend_register_internal_class_ex(&ce, php_v8_primitive_class_entry);
54+
55+
return SUCCESS;
56+
}

src/php_v8_undefined.h

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* This file is part of the pinepain/php-v8 PHP extension.
3+
*
4+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
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_UNDEFINED_H
14+
#define PHP_V8_UNDEFINED_H
15+
16+
extern "C" {
17+
#include "php.h"
18+
19+
#ifdef ZTS
20+
#include "TSRM.h"
21+
#endif
22+
}
23+
24+
extern zend_class_entry* php_v8_undefined_class_entry;
25+
26+
27+
PHP_MINIT_FUNCTION(php_v8_undefined);
28+
29+
#endif //PHP_V8_UNDEFINED_H

src/php_v8_value.cc

+14-13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "php_v8_uint32.h"
3939
#include "php_v8_integer.h"
4040
#include "php_v8_number.h"
41+
#include "php_v8_undefined.h"
4142
/* end of type listing */
4243

4344
#include "php_v8_data.h"
@@ -231,7 +232,7 @@ zend_class_entry *php_v8_get_class_entry_from_value(v8::Local<v8::Value> value)
231232
// working with scalars
232233

233234
if (value->IsUndefined()) {
234-
return php_v8_value_class_entry;
235+
return php_v8_undefined_class_entry;
235236
}
236237

237238
if (value->IsNull()) {
@@ -313,17 +314,15 @@ php_v8_value_t *php_v8_get_or_create_value(zval *return_value, v8::Local<v8::Val
313314
}
314315

315316

316-
static PHP_METHOD (V8Value, __construct) {
317-
zval *php_v8_isolate_zv;
318-
319-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) {
320-
return;
321-
}
322-
323-
PHP_V8_VALUE_CONSTRUCT(getThis(), php_v8_isolate_zv, php_v8_isolate, php_v8_value);
324-
325-
php_v8_value->persistent->Reset(isolate, v8::Undefined(isolate));
326-
}
317+
//static PHP_METHOD (V8Value, __construct) {
318+
// zval *php_v8_isolate_zv;
319+
//
320+
// if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) {
321+
// return;
322+
// }
323+
//
324+
// PHP_V8_THROW_EXCEPTION("V8\\Value::__construct() should not be called. Use specific values instead.")
325+
//}
327326

328327
static PHP_METHOD(V8Value, GetIsolate) {
329328
zval rv;
@@ -1062,7 +1061,8 @@ ZEND_END_ARG_INFO()
10621061

10631062

10641063
static const zend_function_entry php_v8_value_methods[] = {
1065-
PHP_ME(V8Value, __construct, arginfo_v8_value___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
1064+
// PHP_ME(V8Value, __construct, arginfo_v8_value___construct, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
1065+
10661066
PHP_ME(V8Value, GetIsolate, arginfo_v8_value_GetIsolate, ZEND_ACC_PUBLIC)
10671067

10681068
PHP_ME(V8Value, IsUndefined, arginfo_v8_value_IsUndefined, ZEND_ACC_PUBLIC)
@@ -1146,6 +1146,7 @@ PHP_MINIT_FUNCTION (php_v8_value) {
11461146
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "Value", php_v8_value_methods);
11471147
this_ce = zend_register_internal_class_ex(&ce, php_v8_data_class_entry);
11481148
this_ce->create_object = php_v8_value_ctor;
1149+
this_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
11491150

11501151
zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE);
11511152

stubs/src/ArrayObject.php

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class ArrayObject extends ObjectValue
3030
*/
3131
public function __construct(Context $context, int $length = 0)
3232
{
33-
parent::__construct($context);
3433
}
3534

3635
/**

stubs/src/BooleanObject.php

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class BooleanObject extends ObjectValue
2727
*/
2828
public function __construct(Context $context, bool $value)
2929
{
30-
parent::__construct($context);
3130
}
3231

3332
/**

stubs/src/BooleanValue.php

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class BooleanValue extends PrimitiveValue
2727
*/
2828
public function __construct(Isolate $isolate, bool $value)
2929
{
30-
parent::__construct($isolate);
3130
}
3231

3332
/**

stubs/src/NameValue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
/**
2020
* A superclass for symbols and strings.
2121
*/
22-
class NameValue extends PrimitiveValue
22+
abstract class NameValue extends PrimitiveValue
2323
{
2424
/**
2525
* Returns the identity hash for this object. The current implementation

stubs/src/NullValue.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
namespace V8;
1717

1818

19-
class NullValue extends Value
19+
class NullValue extends PrimitiveValue
2020
{
21+
public function __construct(Isolate $isolate)
22+
{
23+
}
24+
2125
/**
2226
* @return null
2327
*/

stubs/src/NumberValue.php

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class NumberValue extends PrimitiveValue
2626
*/
2727
public function __construct(Isolate $isolate, float $value)
2828
{
29-
parent::__construct($isolate);
3029
}
3130

3231
/**

stubs/src/PrimitiveValue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
/**
2020
* The superclass of primitive values. See ECMA-262 4.3.2.
2121
*/
22-
class PrimitiveValue extends Value
22+
abstract class PrimitiveValue extends Value
2323
{
2424
}

stubs/src/StringValue.php

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class StringValue extends NameValue
2929
*/
3030
public function __construct(Isolate $isolate, $data = '')
3131
{
32-
parent::__construct($isolate);
3332
}
3433

3534
/**

stubs/src/SymbolValue.php

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class SymbolValue extends NameValue
3131
*/
3232
public function __construct(Isolate $isolate, StringValue $name = null)
3333
{
34-
parent::__construct($isolate);
3534
}
3635

3736
/**

stubs/src/UndefinedValue.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the pinepain/php-v8 PHP extension.
5+
*
6+
* Copyright (c) 2015-2017 Bogdan Padalko <[email protected]>
7+
*
8+
* Licensed under the MIT license: http://opensource.org/licenses/MIT
9+
*
10+
* For the full copyright and license information, please view the
11+
* LICENSE file that was distributed with this source or visit
12+
* http://opensource.org/licenses/MIT
13+
*/
14+
15+
16+
namespace V8;
17+
18+
/**
19+
* A primitive undefined value (ECMA-262, 4.3.10). Sole value is the undefined value.
20+
*/
21+
class UndefinedValue extends PrimitiveValue
22+
{
23+
public function __construct(Isolate $isolate)
24+
{
25+
}
26+
}

stubs/src/Value.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,13 @@
1919
/**
2020
* The superclass of all JavaScript values and objects.
2121
*/
22-
class Value extends Data
22+
abstract class Value extends Data
2323
{
24-
/**
25-
* @var \V8\Isolate
26-
*/
27-
private $isolate;
28-
29-
/**
30-
* @param Isolate $isolate
31-
*/
32-
public function __construct(\V8\Isolate $isolate)
33-
{
34-
$this->isolate = $isolate;
35-
}
36-
3724
/**
3825
* @return \V8\Isolate
3926
*/
40-
public function GetIsolate()
27+
public function GetIsolate(): Isolate
4128
{
42-
return $this->isolate;
4329
}
4430

4531
/**

tests/.tracking_dtors.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ class FunctionObject extends \V8\FunctionObject {
5858
use DestructMessageAwareTrait;
5959
}
6060

61-
class Value extends \V8\Value {
61+
class UndefinedValue extends \V8\UndefinedValue {
6262
use DestructMessageAwareTrait;
6363
}

tests/V8FunctionCallbackInfo.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ object(V8\FunctionCallbackInfo)#10 (8) {
254254
}
255255
}
256256
["new_target":"V8\FunctionCallbackInfo":private]=>
257-
object(V8\Value)#14 (1) {
257+
object(V8\UndefinedValue)#14 (1) {
258258
["isolate":"V8\Value":private]=>
259259
object(v8Tests\TrackingDtors\Isolate)#2 (5) {
260260
["snapshot":"V8\Isolate":private]=>
@@ -495,7 +495,7 @@ object(V8\FunctionCallbackInfo)#10 (8) {
495495
}
496496
}
497497
["new_target":"V8\FunctionCallbackInfo":private]=>
498-
object(V8\Value)#14 (1) {
498+
object(V8\UndefinedValue)#14 (1) {
499499
["isolate":"V8\Value":private]=>
500500
object(v8Tests\TrackingDtors\Isolate)#2 (5) {
501501
["snapshot":"V8\Isolate":private]=>

tests/V8FunctionObject_Call.phpt

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ $v8_helper->CHECK_EQ(10.11, $a4->Get($context, new \V8\IntegerValue($isolate, 3)
127127
$helper->line();
128128

129129
// Local<v8::Value> r1 = ReturnThisSloppy->Call(v8::Undefined(isolate), 0, NULL);
130-
$r1 = $ReturnThisSloppy->Call($context, new \V8\Value($isolate), []);
130+
$r1 = $ReturnThisSloppy->Call($context, new \V8\UndefinedValue($isolate), []);
131131
// CHECK(r1->StrictEquals(context->Global()));
132132
$v8_helper->CHECK($r1->StrictEquals($context->GlobalObject()), '$r1->StrictEquals($context->GlobalObject())');
133133
// Local<v8::Value> r2 = ReturnThisSloppy->Call(v8::Null(isolate), 0, NULL);
@@ -165,7 +165,7 @@ $v8_helper->CHECK($r5->ValueOf(), '$r5->ValueOf()');
165165
$helper->line();
166166

167167
// Local<v8::Value> r6 = ReturnThisStrict->Call(v8::Undefined(isolate), 0, NULL);
168-
$r6 = $ReturnThisStrict->Call($context, new \V8\Value($isolate), []);
168+
$r6 = $ReturnThisStrict->Call($context, new \V8\UndefinedValue($isolate), []);
169169
// CHECK(r6->IsUndefined());
170170
$v8_helper->CHECK($r6->IsUndefined(), '$r6->IsUndefined()');
171171
// Local<v8::Value> r7 = ReturnThisStrict->Call(v8::Null(isolate), 0, NULL);

0 commit comments

Comments
 (0)