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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 56 additions & 0 deletions
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

Lines changed: 29 additions & 0 deletions
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

Lines changed: 14 additions & 13 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)