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

Commit f780fe9

Browse files
committed
Add Isolate::SetRAILMode(), closes #60
1 parent 3049be1 commit f780fe9

15 files changed

+157
-12
lines changed

src/php_v8_enums.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ zend_class_entry* php_v8_property_handler_flags_class_entry;
2525
zend_class_entry *php_v8_property_filter_class_entry;
2626
zend_class_entry *php_v8_key_collection_mode_class_entry;
2727
zend_class_entry *php_v8_index_filter_class_entry;
28+
zend_class_entry *php_v8_rail_mode_class_entry;
2829

2930

3031
static const zend_function_entry php_v8_enum_methods[] = {
@@ -126,5 +127,17 @@ PHP_MINIT_FUNCTION (php_v8_enums) {
126127
zend_declare_class_constant_long(this_ce, ZEND_STRL("SKIP_INDICES"), static_cast<zend_long>(v8::IndexFilter::kSkipIndices));
127128
#undef this_ce
128129

130+
// v8::RAILMode
131+
#define this_ce php_v8_index_filter_class_entry
132+
INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "RAILMode", php_v8_enum_methods);
133+
this_ce = zend_register_internal_class(&ce);
134+
this_ce->ce_flags |= ZEND_ACC_FINAL;
135+
136+
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_RESPONSE"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_RESPONSE));
137+
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_ANIMATION"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_ANIMATION));
138+
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_IDLE"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_IDLE));
139+
zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_LOAD"), static_cast<zend_long>(v8::RAILMode::PERFORMANCE_LOAD));
140+
#undef this_ce
141+
129142
return SUCCESS;
130143
}

src/php_v8_enums.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern zend_class_entry* php_v8_property_handler_flags_class_entry;
3131
extern zend_class_entry* php_v8_property_filter_class_entry;
3232
extern zend_class_entry* php_v8_key_collection_mode_class_entry;
3333
extern zend_class_entry* php_v8_index_filter_class_entry;
34+
extern zend_class_entry *php_v8_rail_mode_class_entry;
3435

3536

3637
#define PHP_V8_ACCESS_CONTROL_FLAGS ( 0 \
@@ -77,12 +78,11 @@ extern zend_class_entry* php_v8_index_filter_class_entry;
7778
| static_cast<long>(v8::KeyCollectionMode::kIncludePrototypes) \
7879
)
7980

80-
#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \
81-
| static_cast<long>(v8::IndexFilter::kIncludeIndices) \
82-
| static_cast<long>(v8::IndexFilter::kSkipIndices) \
81+
#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \
82+
| static_cast<long>(v8::IndexFilter::kIncludeIndices) \
83+
| static_cast<long>(v8::IndexFilter::kSkipIndices) \
8384
)
8485

85-
8686
PHP_MINIT_FUNCTION (php_v8_enums);
8787

8888
#endif //PHP_V8_ENUMS_H

src/php_v8_isolate.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "php_v8_stack_trace.h"
2424
#include "php_v8_object.h"
2525
#include "php_v8_value.h"
26+
#include "php_v8_enums.h"
2627
#include "php_v8_a.h"
2728
#include "php_v8.h"
2829

@@ -424,6 +425,21 @@ static PHP_METHOD(Isolate, lowMemoryNotification) {
424425
isolate->LowMemoryNotification();
425426
}
426427

428+
static PHP_METHOD(Isolate, setRAILMode) {
429+
zend_long rail_mode = -1;
430+
431+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &rail_mode) == FAILURE) {
432+
return;
433+
}
434+
435+
PHP_V8_CHECK_ISOLATE_RAIL_MODE(rail_mode, "Invalid RAIL mode given. See V8\\RAILMode class constants for available values.")
436+
437+
PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate);
438+
PHP_V8_ENTER_ISOLATE(php_v8_isolate);
439+
440+
isolate->SetRAILMode(static_cast<v8::RAILMode>(rail_mode));
441+
}
442+
427443
static PHP_METHOD(Isolate, terminateExecution) {
428444
if (zend_parse_parameters_none() == FAILURE) {
429445
return;
@@ -549,6 +565,10 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_idleNotificationDeadline,
549565
ZEND_ARG_INFO(0, deadline_in_seconds)
550566
ZEND_END_ARG_INFO()
551567

568+
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_setRAILMode, 1)
569+
ZEND_ARG_TYPE_INFO(0, rail_mode, IS_LONG, 0)
570+
ZEND_END_ARG_INFO()
571+
552572
PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_lowMemoryNotification, 0)
553573
ZEND_END_ARG_INFO()
554574

@@ -588,6 +608,7 @@ static const zend_function_entry php_v8_isolate_methods[] = {
588608
PHP_V8_ME(Isolate, throwException, ZEND_ACC_PUBLIC)
589609
PHP_V8_ME(Isolate, idleNotificationDeadline, ZEND_ACC_PUBLIC)
590610
PHP_V8_ME(Isolate, lowMemoryNotification, ZEND_ACC_PUBLIC)
611+
PHP_V8_ME(Isolate, setRAILMode, ZEND_ACC_PUBLIC)
591612
PHP_V8_ME(Isolate, terminateExecution, ZEND_ACC_PUBLIC)
592613
PHP_V8_ME(Isolate, isExecutionTerminating, ZEND_ACC_PUBLIC)
593614
PHP_V8_ME(Isolate, cancelTerminateExecution, ZEND_ACC_PUBLIC)

src/php_v8_isolate.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ inline v8::Local<v8::Private> php_v8_isolate_get_key_local(php_v8_isolate_t *php
122122
return; \
123123
}
124124

125+
#define PHP_V8_CHECK_ISOLATE_RAIL_MODE(mode, message) \
126+
if (mode < static_cast<zend_long>(v8::RAILMode::PERFORMANCE_RESPONSE) \
127+
|| mode > static_cast<zend_long>(v8::RAILMode::PERFORMANCE_LOAD)) { \
128+
PHP_V8_THROW_VALUE_EXCEPTION(message); \
129+
return; \
130+
}
131+
125132

126133
struct _php_v8_isolate_t {
127134
v8::Isolate *isolate;

stubs/src/AccessControl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace V8;
1717

18-
class AccessControl
18+
final class AccessControl
1919
{
2020
const DEFAULT_ACCESS = 0; // do not allow cross-context access
2121
const ALL_CAN_READ = 1; // all cross-context reads are allowed

stubs/src/ConstructorBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace V8;
1717

1818

19-
class ConstructorBehavior
19+
final class ConstructorBehavior
2020
{
2121
const THROW = 0;
2222
const ALLOW = 1;

stubs/src/IntegrityLevel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Integrity level for objects.
2020
*/
21-
class IntegrityLevel
21+
final class IntegrityLevel
2222
{
2323
const FROZEN = 0;
2424
const SEALED = 1;

stubs/src/Isolate.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ public function lowMemoryNotification()
188188
{
189189
}
190190

191+
/**
192+
* Optional notification to tell V8 the current performance requirements
193+
* of the embedder based on RAIL.
194+
* V8 uses these notifications to guide heuristics.
195+
* This is an unfinished experimental feature. Semantics and implementation
196+
* may change frequently.
197+
*
198+
* @param int $rail_mode
199+
*
200+
* @return void
201+
*/
202+
public function setRAILMode(int $rail_mode)
203+
{
204+
}
205+
191206
/**
192207
* Check if V8 is dead and therefore unusable. This is the case after
193208
* fatal errors such as out-of-memory situations.

stubs/src/KeyCollectionMode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
/**
1919
* Keys/Properties filter to limits the range of collected properties
2020
*/
21-
class KeyCollectionMode
21+
final class KeyCollectionMode
2222
{
2323
const kOwnOnly = 0; // limits the collected properties to the given Object only. kIncludesPrototypes
2424
const kIncludesPrototypes = 1; // will include all keys of the objects's prototype chain as well.

stubs/src/PropertyAttribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
namespace V8;
1717

1818

19-
class PropertyAttribute
19+
final class PropertyAttribute
2020
{
2121
const NONE = 0;
2222
const READ_ONLY = 1;

0 commit comments

Comments
 (0)