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

Commit 2bb166f

Browse files
committed
Add V8\SymbolValue::GetToPrimitive() method
v8/v8@34bee46
1 parent d4bc854 commit 2bb166f

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

src/php_v8_symbol.cc

+23
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@ static PHP_METHOD(V8Symbol, GetUnscopables)
156156
php_v8_get_or_create_value(return_value, local_symbol, isolate);
157157
}
158158

159+
static PHP_METHOD(V8Symbol, GetToPrimitive)
160+
{
161+
zval *php_v8_isolate_zv;
162+
163+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o", &php_v8_isolate_zv) == FAILURE) {
164+
return;
165+
}
166+
167+
PHP_V8_ISOLATE_FETCH_WITH_CHECK(php_v8_isolate_zv, php_v8_isolate);
168+
PHP_V8_ENTER_ISOLATE(php_v8_isolate);
169+
170+
v8::Local<v8::Symbol> local_symbol = v8::Symbol::GetToPrimitive(isolate);
171+
172+
PHP_V8_THROW_VALUE_EXCEPTION_WHEN_EMPTY(local_symbol, "Failed to create Symbol value");
173+
174+
php_v8_get_or_create_value(return_value, local_symbol, isolate);
175+
}
176+
159177
static PHP_METHOD(V8Symbol, GetToStringTag)
160178
{
161179
zval *php_v8_isolate_zv;
@@ -219,6 +237,10 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetUnscopables,
219237
ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0)
220238
ZEND_END_ARG_INFO()
221239

240+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetToPrimitive, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0)
241+
ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0)
242+
ZEND_END_ARG_INFO()
243+
222244
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_symbol_GetToStringTag, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0)
223245
ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0)
224246
ZEND_END_ARG_INFO()
@@ -238,6 +260,7 @@ static const zend_function_entry php_v8_symbol_methods[] = {
238260

239261
PHP_ME(V8Symbol, GetIterator, arginfo_v8_symbol_GetIterator, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
240262
PHP_ME(V8Symbol, GetUnscopables, arginfo_v8_symbol_GetUnscopables, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
263+
PHP_ME(V8Symbol, GetToPrimitive, arginfo_v8_symbol_GetToPrimitive, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
241264
PHP_ME(V8Symbol, GetToStringTag, arginfo_v8_symbol_GetToStringTag, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
242265
PHP_ME(V8Symbol, GetIsConcatSpreadable, arginfo_v8_symbol_GetIsConcatSpreadable, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
243266

stubs/src/SymbolValue.php

+9
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ public static function GetUnscopables(Isolate $isolate) : SymbolValue
9494
{
9595
}
9696

97+
/**
98+
* @param Isolate $isolate
99+
*
100+
* @return SymbolValue
101+
*/
102+
public static function GetToPrimitive(Isolate $isolate) : SymbolValue
103+
{
104+
}
105+
97106
/**
98107
* @param Isolate $isolate
99108
*

tests/V8SymbolValue.phpt

+13-3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ $helper->assert('Symbol GetUnscopables() returned', $value instanceof \V8\Symbol
157157
$helper->pretty_dump('Symbol GetUnscopables() name', $value->Name()->Value());
158158
$helper->line();
159159

160+
$helper->assert('Isolate not in context', !$isolate->InContext());
161+
$value = V8\SymbolValue::GetToPrimitive($isolate);
162+
$helper->assert('Symbol GetToPrimitive() returned', $value instanceof \V8\SymbolValue);
163+
$helper->pretty_dump('Symbol GetToPrimitive() name', $value->Name()->Value());
164+
$helper->line();
165+
160166
$helper->assert('Isolate not in context', !$isolate->InContext());
161167
$value = V8\SymbolValue::GetToStringTag($isolate);
162168
$helper->assert('Symbol GetToStringTag() returned', $value instanceof \V8\SymbolValue);
@@ -199,7 +205,7 @@ Accessors:
199205
----------
200206
V8\SymbolValue::GetIsolate() matches expected value
201207
V8\SymbolValue->Name():
202-
object(V8\Value)#85 (1) {
208+
object(V8\Value)#86 (1) {
203209
["isolate":"V8\Value":private]=>
204210
object(V8\Isolate)#3 (5) {
205211
["snapshot":"V8\Isolate":private]=>
@@ -276,7 +282,7 @@ Null constructor:
276282

277283
Object representation:
278284
----------------------
279-
object(V8\SymbolValue)#85 (1) {
285+
object(V8\SymbolValue)#86 (1) {
280286
["isolate":"V8\Value":private]=>
281287
object(V8\Isolate)#3 (5) {
282288
["snapshot":"V8\Isolate":private]=>
@@ -503,7 +509,7 @@ Accessors:
503509
----------
504510
V8\SymbolValue::GetIsolate() matches expected value
505511
V8\SymbolValue->Name():
506-
object(V8\StringValue)#86 (1) {
512+
object(V8\StringValue)#87 (1) {
507513
["isolate":"V8\Value":private]=>
508514
object(V8\Isolate)#3 (5) {
509515
["snapshot":"V8\Isolate":private]=>
@@ -706,6 +712,10 @@ Isolate not in context: ok
706712
Symbol GetUnscopables() returned: ok
707713
Symbol GetUnscopables() name: string(18) "Symbol.unscopables"
708714

715+
Isolate not in context: ok
716+
Symbol GetToPrimitive() returned: ok
717+
Symbol GetToPrimitive() name: string(18) "Symbol.toPrimitive"
718+
709719
Isolate not in context: ok
710720
Symbol GetToStringTag() returned: ok
711721
Symbol GetToStringTag() name: string(18) "Symbol.toStringTag"

0 commit comments

Comments
 (0)