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

Commit b62b02f

Browse files
committedSep 2, 2017
Make enum classes with constants finall, closes #39
1 parent 9d99e7a commit b62b02f

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed
 

‎src/php_v8_enums.cc

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
3939
#define this_ce php_v8_access_control_class_entry
4040
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "AccessControl", php_v8_enum_methods);
4141
this_ce = zend_register_internal_class(&ce);
42+
this_ce->ce_flags |= ZEND_ACC_FINAL;
4243

4344
zend_declare_class_constant_long(this_ce, ZEND_STRL("DEFAULT_ACCESS"), v8::AccessControl::DEFAULT);
4445
zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_CAN_READ"), v8::AccessControl::ALL_CAN_READ);
@@ -49,6 +50,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
4950
#define this_ce php_v8_constructor_behavior_class_entry
5051
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "ConstructorBehavior", php_v8_enum_methods);
5152
this_ce = zend_register_internal_class(&ce);
53+
this_ce->ce_flags |= ZEND_ACC_FINAL;
5254

5355
zend_declare_class_constant_long(this_ce, ZEND_STRL("THROW"), static_cast<long>(v8::ConstructorBehavior::kThrow));
5456
zend_declare_class_constant_long(this_ce, ZEND_STRL("ALLOW"), static_cast<long>(v8::ConstructorBehavior::kAllow));
@@ -59,6 +61,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
5961
#define this_ce php_v8_integrity_level_class_entry
6062
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "IntegrityLevel", php_v8_enum_methods);
6163
this_ce = zend_register_internal_class(&ce);
64+
this_ce->ce_flags |= ZEND_ACC_FINAL;
6265

6366
zend_declare_class_constant_long(this_ce, ZEND_STRL("FROZEN"), static_cast<zend_long>(v8::IntegrityLevel::kFrozen));
6467
zend_declare_class_constant_long(this_ce, ZEND_STRL("SEALED"), static_cast<zend_long>(v8::IntegrityLevel::kSealed));
@@ -68,6 +71,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
6871
#define this_ce php_v8_property_attribute_class_entry
6972
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyAttribute", php_v8_enum_methods);
7073
this_ce = zend_register_internal_class(&ce);
74+
this_ce->ce_flags |= ZEND_ACC_FINAL;
7175

7276
zend_declare_class_constant_long(this_ce, ZEND_STRL("NONE"), v8::PropertyAttribute::None);
7377
zend_declare_class_constant_long(this_ce, ZEND_STRL("READ_ONLY"), v8::PropertyAttribute::ReadOnly);
@@ -80,6 +84,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
8084
#define this_ce php_v8_property_handler_flags_class_entry
8185
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyHandlerFlags", php_v8_enum_methods);
8286
this_ce = zend_register_internal_class(&ce);
87+
this_ce->ce_flags |= ZEND_ACC_FINAL;
8388

8489
zend_declare_class_constant_long(this_ce, ZEND_STRL("NONE"), static_cast<zend_long>(v8::PropertyHandlerFlags::kNone));
8590
zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_CAN_READ"), static_cast<zend_long>(v8::PropertyHandlerFlags::kAllCanRead));
@@ -91,6 +96,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
9196
#define this_ce php_v8_property_filter_class_entry
9297
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyFilter", php_v8_enum_methods);
9398
this_ce = zend_register_internal_class(&ce);
99+
this_ce->ce_flags |= ZEND_ACC_FINAL;
94100

95101
zend_declare_class_constant_long(this_ce, ZEND_STRL("ALL_PROPERTIES"), v8::PropertyFilter::ALL_PROPERTIES);
96102
zend_declare_class_constant_long(this_ce, ZEND_STRL("ONLY_WRITABLE"), v8::PropertyFilter::ONLY_WRITABLE);
@@ -104,6 +110,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
104110
#define this_ce php_v8_key_collection_mode_class_entry
105111
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "KeyCollectionMode", php_v8_enum_methods);
106112
this_ce = zend_register_internal_class(&ce);
113+
this_ce->ce_flags |= ZEND_ACC_FINAL;
107114

108115
zend_declare_class_constant_long(this_ce, ZEND_STRL("OWN_ONLY"), static_cast<zend_long>(v8::KeyCollectionMode::kOwnOnly));
109116
zend_declare_class_constant_long(this_ce, ZEND_STRL("INCLUDE_PROTOTYPES"), static_cast<zend_long>(v8::KeyCollectionMode::kIncludePrototypes));
@@ -113,6 +120,7 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
113120
#define this_ce php_v8_index_filter_class_entry
114121
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "IndexFilter", php_v8_enum_methods);
115122
this_ce = zend_register_internal_class(&ce);
123+
this_ce->ce_flags |= ZEND_ACC_FINAL;
116124

117125
zend_declare_class_constant_long(this_ce, ZEND_STRL("INCLUDE_INDICES"), static_cast<zend_long>(v8::IndexFilter::kIncludeIndices));
118126
zend_declare_class_constant_long(this_ce, ZEND_STRL("SKIP_INDICES"), static_cast<zend_long>(v8::IndexFilter::kSkipIndices));

‎src/php_v8_regexp.cc

+11-8
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,19 @@ PHP_MINIT_FUNCTION(php_v8_regexp) {
112112
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "RegExpObject", php_v8_regexp_methods);
113113
this_ce = zend_register_internal_class_ex(&ce, php_v8_object_class_entry);
114114

115+
#undef this_ce
116+
#define this_ce php_v8_regexp_flags_class_entry
115117

116118
INIT_NS_CLASS_ENTRY(ce, "V8\\RegExpObject", "Flags", php_v8_regexp_flags_methods);
117-
php_v8_regexp_flags_class_entry = zend_register_internal_class(&ce);
118-
119-
zend_declare_class_constant_long(php_v8_regexp_flags_class_entry, ZEND_STRL("NONE"), v8::RegExp::Flags::kNone);
120-
zend_declare_class_constant_long(php_v8_regexp_flags_class_entry, ZEND_STRL("GLOBAL"), v8::RegExp::Flags::kGlobal);
121-
zend_declare_class_constant_long(php_v8_regexp_flags_class_entry, ZEND_STRL("IGNORE_CASE"), v8::RegExp::Flags::kIgnoreCase);
122-
zend_declare_class_constant_long(php_v8_regexp_flags_class_entry, ZEND_STRL("MULTILINE"), v8::RegExp::Flags::kMultiline);
123-
zend_declare_class_constant_long(php_v8_regexp_flags_class_entry, ZEND_STRL("STICKY"), v8::RegExp::Flags::kSticky);
124-
zend_declare_class_constant_long(php_v8_regexp_flags_class_entry, ZEND_STRL("UNICODE"), v8::RegExp::Flags::kUnicode);
119+
this_ce = zend_register_internal_class(&ce);
120+
this_ce->ce_flags |= ZEND_ACC_FINAL;
121+
122+
zend_declare_class_constant_long(this_ce, ZEND_STRL("NONE"), v8::RegExp::Flags::kNone);
123+
zend_declare_class_constant_long(this_ce, ZEND_STRL("GLOBAL"), v8::RegExp::Flags::kGlobal);
124+
zend_declare_class_constant_long(this_ce, ZEND_STRL("IGNORE_CASE"), v8::RegExp::Flags::kIgnoreCase);
125+
zend_declare_class_constant_long(this_ce, ZEND_STRL("MULTILINE"), v8::RegExp::Flags::kMultiline);
126+
zend_declare_class_constant_long(this_ce, ZEND_STRL("STICKY"), v8::RegExp::Flags::kSticky);
127+
zend_declare_class_constant_long(this_ce, ZEND_STRL("UNICODE"), v8::RegExp::Flags::kUnicode);
125128

126129
return SUCCESS;
127130
}

‎src/php_v8_script_compiler.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ PHP_MINIT_FUNCTION(php_v8_script_compiler)
301301
#define this_ce php_v8_compile_options_class_entry
302302

303303
INIT_NS_CLASS_ENTRY(ce, "V8\\ScriptCompiler", "CompileOptions", php_v8_compile_options_methods);
304-
php_v8_compile_options_class_entry = zend_register_internal_class(&ce);
304+
this_ce = zend_register_internal_class(&ce);
305+
this_ce->ce_flags |= ZEND_ACC_FINAL;
305306

306307
zend_declare_class_constant_long(this_ce, ZEND_STRL("NO_COMPILE_OPTIONS"), v8::ScriptCompiler::CompileOptions::kNoCompileOptions);
307308
zend_declare_class_constant_long(this_ce, ZEND_STRL("PRODUCE_PARSER_CACHE"), v8::ScriptCompiler::CompileOptions::kProduceParserCache);

‎tests/002-enums.phpt

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ $enums = [
2424
];
2525

2626
foreach ($enums as $enum) {
27+
$rc = new ReflectionClass($enum);
28+
2729
$helper->header('Object representation');
30+
$helper->assert('Class is final', $rc->isFinal());
2831
$helper->dump($enum);
2932
$helper->space();
3033

31-
3234
$helper->header('Class constants');
3335
$helper->dump_object_constants($enum);
3436
$helper->space();
@@ -39,6 +41,7 @@ foreach ($enums as $enum) {
3941
--EXPECT--
4042
Object representation:
4143
----------------------
44+
Class is final: ok
4245
object(V8\AccessControl)#2 (0) {
4346
}
4447

@@ -52,6 +55,7 @@ V8\AccessControl::ALL_CAN_WRITE = 2
5255

5356
Object representation:
5457
----------------------
58+
Class is final: ok
5559
object(V8\ConstructorBehavior)#3 (0) {
5660
}
5761

@@ -64,6 +68,7 @@ V8\ConstructorBehavior::ALLOW = 1
6468

6569
Object representation:
6670
----------------------
71+
Class is final: ok
6772
object(V8\IntegrityLevel)#4 (0) {
6873
}
6974

@@ -76,6 +81,7 @@ V8\IntegrityLevel::SEALED = 1
7681

7782
Object representation:
7883
----------------------
84+
Class is final: ok
7985
object(V8\PropertyAttribute)#5 (0) {
8086
}
8187

@@ -90,6 +96,7 @@ V8\PropertyAttribute::DONT_DELETE = 4
9096

9197
Object representation:
9298
----------------------
99+
Class is final: ok
93100
object(V8\PropertyHandlerFlags)#6 (0) {
94101
}
95102

@@ -104,6 +111,7 @@ V8\PropertyHandlerFlags::ONLY_INTERCEPT_STRINGS = 4
104111

105112
Object representation:
106113
----------------------
114+
Class is final: ok
107115
object(V8\PropertyFilter)#7 (0) {
108116
}
109117

@@ -120,6 +128,7 @@ V8\PropertyFilter::SKIP_SYMBOLS = 16
120128

121129
Object representation:
122130
----------------------
131+
Class is final: ok
123132
object(V8\KeyCollectionMode)#8 (0) {
124133
}
125134

@@ -132,6 +141,7 @@ V8\KeyCollectionMode::INCLUDE_PROTOTYPES = 1
132141

133142
Object representation:
134143
----------------------
144+
Class is final: ok
135145
object(V8\IndexFilter)#9 (0) {
136146
}
137147

@@ -144,6 +154,7 @@ V8\IndexFilter::SKIP_INDICES = 1
144154

145155
Object representation:
146156
----------------------
157+
Class is final: ok
147158
object(V8\RegExpObject\Flags)#10 (0) {
148159
}
149160

@@ -160,6 +171,7 @@ V8\RegExpObject\Flags::UNICODE = 16
160171

161172
Object representation:
162173
----------------------
174+
Class is final: ok
163175
object(V8\ScriptCompiler\CompileOptions)#11 (0) {
164176
}
165177

0 commit comments

Comments
 (0)
This repository has been archived.