From 5d5f003795b9d798b03d3e3e4d415870dc057e60 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sat, 16 Sep 2017 18:36:13 +0300 Subject: [PATCH 01/17] Require libv8 >= 6.3.163 --- README.md | 2 +- config.m4 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bdc1048..83f295d 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ in your IDE and other code-analysis tools. ### Requirements #### V8 -You will need a recent v8 Google JavaScript engine version installed. At this time v8 >= 6.3.2 required. +You will need a recent v8 Google JavaScript engine version installed. At this time v8 >= 6.3.163 required. #### PHP This extension is PHP7-only. It works and tested with both PHP 7.0 and PHP 7.1. diff --git a/config.m4 b/config.m4 index 255c3c0..a8650e6 100644 --- a/config.m4 +++ b/config.m4 @@ -19,7 +19,7 @@ if test "$PHP_V8" != "no"; then SEARCH_PATH="/usr/local /usr" SEARCH_FOR="include/v8.h" - V8_MIN_API_VERSION_STR=6.3.2 + V8_MIN_API_VERSION_STR=6.3.163 DESIRED_V8_VERSION=`echo "${V8_MIN_API_VERSION_STR}" | $AWK 'BEGIN { FS = "."; } { printf "%s.%s", [$]1, [$]2;}'` From 5477a165a34680240215f0d3bc896f66eff0bf86 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sat, 16 Sep 2017 21:59:04 +0300 Subject: [PATCH 02/17] TZ change notification is a pita in v8, do not use it --- tests/DateObject.phpt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/DateObject.phpt b/tests/DateObject.phpt index 4d477d5..b7300b7 100644 --- a/tests/DateObject.phpt +++ b/tests/DateObject.phpt @@ -187,7 +187,7 @@ V8\DateObject(V8\Value)->isSharedArrayBuffer(): bool(false) V8\DateObject(V8\Value)->isProxy(): bool(false) -val: Wed Oct 21 2015 16:29:00 GMT+0000 (UTC) +val: Wed Oct 21 2015 %s typeof val: object @@ -198,13 +198,13 @@ Expected value is identical to actual value Timezone change (with notification to v8): ------------------------------------------ -val: Wed Oct 21 2015 09:29:00 GMT-0700 (PDT) +val: Wed Oct 21 2015 %s typeof val: object Expected 1445444940000.0 value is identical to actual value 1445444940000.0 Timezone change (without notification to v8): --------------------------------------------- -val: Wed Oct 21 2015 09:29:00 GMT-0700 (%sDT) +val: Wed Oct 21 2015 %s typeof val: object Expected 1445444940000.0 value is identical to actual value 1445444940000.0 From 75c3a40fe4bb169dcbe9d5321e2de4f9e716e6c2 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sat, 16 Sep 2017 22:01:07 +0300 Subject: [PATCH 03/17] Something changed (or fixed) in 6.3.163, just second that --- ...Template_setHandlerForIndexedProperty.phpt | 11 +++++++++- ...ctTemplate_setHandlerForNamedProperty.phpt | 10 +++++++++ tests/ObjectTemplate_setHandler_both.phpt | 21 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/tests/ObjectTemplate_setHandlerForIndexedProperty.phpt b/tests/ObjectTemplate_setHandlerForIndexedProperty.phpt index 4f85a18..bbbdd0a 100644 --- a/tests/ObjectTemplate_setHandlerForIndexedProperty.phpt +++ b/tests/ObjectTemplate_setHandlerForIndexedProperty.phpt @@ -123,9 +123,18 @@ I am indexed getter for 0! test[0]: 21 I am indexed enumerator! I am indexed query for 0! +I am indexed query for 1! +I am indexed query for 2! +I am indexed query for 3! +I am indexed query for 4! +I am indexed query for 5! +I am indexed query for 6! +I am indexed query for 7! +I am indexed query for 8! +I am indexed query for 9! +I am indexed query for 0! I am indexed getter for 0! test[0]: 21 -I am indexed query for 1! I am indexed query for 2! I am indexed getter for 2! test[2]: 21 diff --git a/tests/ObjectTemplate_setHandlerForNamedProperty.phpt b/tests/ObjectTemplate_setHandlerForNamedProperty.phpt index e59017e..cba2e9b 100644 --- a/tests/ObjectTemplate_setHandlerForNamedProperty.phpt +++ b/tests/ObjectTemplate_setHandlerForNamedProperty.phpt @@ -105,6 +105,16 @@ I am named query for foo! "foo" in test: true I am named enumerator! I am named query for test-a! +I am named query for test-b! +I am named query for test-c! +I am named query for test-d! +I am named query for test-e! +I am named query for test-f! +I am named query for test-g! +I am named query for test-h! +I am named query for test-i! +I am named query for test-j! +I am named query for test-a! I am named getter for test-a! test[test-a]: 21 I am named query for test-b! diff --git a/tests/ObjectTemplate_setHandler_both.phpt b/tests/ObjectTemplate_setHandler_both.phpt index 272fb51..9e595ac 100644 --- a/tests/ObjectTemplate_setHandler_both.phpt +++ b/tests/ObjectTemplate_setHandler_both.phpt @@ -193,6 +193,16 @@ I am named query for foo! I am indexed enumerator! I am named enumerator! I am named query for test-a! +I am named query for test-b! +I am named query for test-c! +I am named query for test-d! +I am named query for test-e! +I am named query for test-f! +I am named query for test-g! +I am named query for test-h! +I am named query for test-i! +I am named query for test-j! +I am named query for test-a! I am named getter for test-a! test[test-a]: 21 I am named query for test-b! @@ -241,11 +251,20 @@ delete test[0]: true I am indexed getter for 0! test[0]: 21 I am indexed enumerator! +I am indexed query for 0! +I am indexed query for 1! +I am indexed query for 2! +I am indexed query for 3! +I am indexed query for 4! +I am indexed query for 5! +I am indexed query for 6! +I am indexed query for 7! +I am indexed query for 8! +I am indexed query for 9! I am named enumerator! I am indexed query for 0! I am indexed getter for 0! test[0]: 21 -I am indexed query for 1! I am indexed query for 2! I am indexed getter for 2! test[2]: 21 From 3bacc5cdd62501027bf6c390ba2c248bc5bdeb23 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sat, 16 Sep 2017 21:35:47 +0300 Subject: [PATCH 04/17] Cleanup stubs [skip ci] --- stubs/src/AccessControl.php | 4 +-- stubs/src/CallbackInfo.php | 10 +++---- stubs/src/Context.php | 23 +++++++-------- stubs/src/ExceptionManager.php | 30 +++++++++---------- stubs/src/Exceptions/TryCatchException.php | 1 + stubs/src/FunctionCallbackInfo.php | 4 +-- stubs/src/FunctionObject.php | 30 +++++++++---------- stubs/src/FunctionTemplate.php | 8 ++--- stubs/src/IndexFilter.php | 2 +- stubs/src/Isolate.php | 2 +- stubs/src/KeyCollectionMode.php | 2 +- stubs/src/MapObject.php | 2 +- stubs/src/ObjectTemplate.php | 10 +++---- stubs/src/ObjectValue.php | 18 ++++++------ stubs/src/PromiseObject.php | 2 +- stubs/src/ProxyObject.php | 2 +- stubs/src/ReturnValue.php | 8 ++--- stubs/src/Script.php | 8 ++--- stubs/src/SetObject.php | 2 +- stubs/src/StackTrace.php | 2 +- stubs/src/StringObject.php | 6 ++-- stubs/src/StringValue.php | 2 +- stubs/src/SymbolValue.php | 4 +-- stubs/src/Template.php | 20 ++++++------- stubs/src/TryCatch.php | 34 +++++++++++----------- stubs/src/UnboundScript.php | 6 ++-- stubs/src/Value.php | 20 ++++++------- 27 files changed, 130 insertions(+), 132 deletions(-) diff --git a/stubs/src/AccessControl.php b/stubs/src/AccessControl.php index 0fe9009..7632d4b 100644 --- a/stubs/src/AccessControl.php +++ b/stubs/src/AccessControl.php @@ -18,6 +18,6 @@ class AccessControl { const DEFAULT_ACCESS = 0; // do not allow cross-context access - const ALL_CAN_READ = 1; // all cross-context reads are allowed - const ALL_CAN_WRITE = 2; // all cross-context writes are allowed + const ALL_CAN_READ = 1; // all cross-context reads are allowed + const ALL_CAN_WRITE = 2; // all cross-context writes are allowed } diff --git a/stubs/src/CallbackInfo.php b/stubs/src/CallbackInfo.php index d42839d..937158b 100644 --- a/stubs/src/CallbackInfo.php +++ b/stubs/src/CallbackInfo.php @@ -18,14 +18,14 @@ class CallbackInfo { /** - * @return \V8\Isolate + * @return Isolate */ public function getIsolate(): Isolate { } /** - * @return \V8\Context + * @return Context */ public function getContext(): Context { @@ -34,7 +34,7 @@ public function getContext(): Context /** * Returns the receiver. This corresponds to the "this" value. * - * @return \V8\ObjectValue + * @return ObjectValue */ public function this(): ObjectValue { @@ -50,7 +50,7 @@ public function this(): ObjectValue * referencing this callback was found (which in V8 internally is often * referred to as holder [sic]). * - * @return \V8\ObjectValue + * @return ObjectValue */ public function holder(): ObjectValue { @@ -59,7 +59,7 @@ public function holder(): ObjectValue /** * The ReturnValue for the call * - * @return \V8\ReturnValue + * @return ReturnValue */ public function getReturnValue(): ReturnValue { diff --git a/stubs/src/Context.php b/stubs/src/Context.php index 90b3bde..ad20506 100644 --- a/stubs/src/Context.php +++ b/stubs/src/Context.php @@ -22,7 +22,7 @@ class Context { /** - * @var \V8\Isolate + * @var Isolate */ private $isolate; @@ -41,21 +41,18 @@ class Context * template. The state of the global object will be completely reset * and only object identify will remain. * - * @param \V8\Isolate $isolate - * @param \V8\ObjectTemplate|null $global_template - * @param \V8\ObjectValue|null $global_object + * @param Isolate $isolate + * @param ObjectTemplate|null $global_template + * @param ObjectValue|null $global_object * * @internal param array|null $extensions Currently unused as there are not extensions support */ - public function __construct( - Isolate $isolate, - ObjectTemplate $global_template = null, - ObjectValue $global_object = null - ) { + public function __construct(Isolate $isolate, ObjectTemplate $global_template = null, ObjectValue $global_object = null) + { } /** - * @return \V8\Isolate + * @return Isolate */ public function getIsolate(): Isolate { @@ -74,7 +71,7 @@ public function getIsolate(): Isolate * would break VM---v8 expects only global object as a prototype of global * proxy object. * - * @return \V8\ObjectValue + * @return ObjectValue */ public function globalObject(): ObjectValue { @@ -93,7 +90,7 @@ public function detachGlobal() * Sets the security token for the context. To access an object in * another context, the security tokens must match. * - * @param \V8\Value $token + * @param Value $token */ public function setSecurityToken(Value $token) { @@ -109,7 +106,7 @@ public function useDefaultSecurityToken() /** * Returns the security token of this context. * - * @return \V8\Value + * @return Value|PrimitiveValue|ObjectValue */ public function getSecurityToken(): Value { diff --git a/stubs/src/ExceptionManager.php b/stubs/src/ExceptionManager.php index 0c0c3c0..2487c82 100644 --- a/stubs/src/ExceptionManager.php +++ b/stubs/src/ExceptionManager.php @@ -23,48 +23,48 @@ class ExceptionManager { /** - * @param Context $context - * @param \V8\StringValue $message + * @param Context $context + * @param StringValue $message * - * @return \V8\ObjectValue + * @return ObjectValue */ public static function createRangeError(Context $context, StringValue $message): ObjectValue { } /** - * @param Context $context - * @param \V8\StringValue $message + * @param Context $context + * @param StringValue $message * - * @return \V8\ObjectValue + * @return ObjectValue */ public static function createReferenceError(Context $context, StringValue $message): ObjectValue { } /** - * @param Context $context - * @param \V8\StringValue $message + * @param Context $context + * @param StringValue $message * - * @return \V8\ObjectValue + * @return ObjectValue */ public static function createSyntaxError(Context $context, StringValue $message): ObjectValue { } /** - * @param Context $context - * @param \V8\StringValue $message + * @param Context $context + * @param StringValue $message * - * @return \V8\ObjectValue + * @return ObjectValue */ public static function createTypeError(Context $context, StringValue $message): ObjectValue { } /** - * @param Context $context - * @param \V8\StringValue $message + * @param Context $context + * @param StringValue $message * * @return ObjectValue */ @@ -82,7 +82,7 @@ public static function createError(Context $context, StringValue $message): Obje * * @return Message */ - public static function createMessage(Context $context, Value $exception): Message + public static function createMessage(Context $context, Value $exception): Message { } diff --git a/stubs/src/Exceptions/TryCatchException.php b/stubs/src/Exceptions/TryCatchException.php index b06593e..ff326b5 100644 --- a/stubs/src/Exceptions/TryCatchException.php +++ b/stubs/src/Exceptions/TryCatchException.php @@ -20,6 +20,7 @@ use V8\Isolate; use V8\TryCatch; + class TryCatchException extends Exception { /** diff --git a/stubs/src/FunctionCallbackInfo.php b/stubs/src/FunctionCallbackInfo.php index 616ab3b..9cecf8e 100644 --- a/stubs/src/FunctionCallbackInfo.php +++ b/stubs/src/FunctionCallbackInfo.php @@ -34,7 +34,7 @@ public function length(): int /** * Get available arguments * - * @return Value[] | StringValue[] | SymbolValue[] | NumberValue[] | ObjectValue[] | ArrayObject[] | FunctionObject[] | StringObject[] | SymbolObject[] + * @return Value[] */ public function arguments(): array { @@ -43,7 +43,7 @@ public function arguments(): array /** * For construct calls, this returns the "new.target" value. * - * @return Value + * @return Value|PrimitiveValue|ObjectValue */ public function newTarget(): Value { diff --git a/stubs/src/FunctionObject.php b/stubs/src/FunctionObject.php index f051495..0fe4b4b 100644 --- a/stubs/src/FunctionObject.php +++ b/stubs/src/FunctionObject.php @@ -25,10 +25,10 @@ class FunctionObject extends ObjectValue * Create a function in the current execution context * for a given FunctionCallback. * - * @param \V8\Context $context - * @param callable $callback - * @param int $length - * @param int $behavior + * @param Context $context + * @param callable $callback + * @param int $length + * @param int $behavior */ public function __construct(Context $context, callable $callback, int $length = 0, int $behavior = ConstructorBehavior::ALLOW) { @@ -36,21 +36,21 @@ public function __construct(Context $context, callable $callback, int $length = } /** - * @param \V8\Context $context - * @param \V8\Value[] $arguments + * @param Context $context + * @param Value[] $arguments * - * @return \V8\ObjectValue + * @return ObjectValue */ public function newInstance(Context $context, array $arguments = []): ObjectValue { } /** - * @param \V8\Context $context - * @param \V8\Value $recv - * @param \V8\Value[] $arguments + * @param Context $context + * @param Value $recv + * @param Value[] $arguments * - * @return \V8\Value + * @return Value|PrimitiveValue|ObjectValue */ public function call(Context $context, Value $recv, array $arguments = []): Value { @@ -64,7 +64,7 @@ public function setName(StringValue $name) } /** - * @return \V8\Value | StringValue + * @return Value|StringValue */ public function getName(): Value { @@ -76,7 +76,7 @@ public function getName(): Value * in an OO style, where many functions are anonymous but are assigned * to object properties. * - * @return \V8\Value | StringValue + * @return Value|StringValue */ public function getInferredName(): Value { @@ -86,7 +86,7 @@ public function getInferredName(): Value * User-defined name assigned to the "displayName" property of this function. * Used to facilitate debugging and profiling of JavaScript code. * - * @return \V8\Value | StringValue + * @return Value|StringValue */ public function getDisplayName(): Value { @@ -125,7 +125,7 @@ public function getScriptId(): ?int /** * Returns the original function if this function is bound, else returns UndefinedValue. * - * @return FunctionObject|UndefinedValue|Value + * @return Value|FunctionObject|UndefinedValue */ public function getBoundFunction(): Value { diff --git a/stubs/src/FunctionTemplate.php b/stubs/src/FunctionTemplate.php index 3eca7b1..60f24bf 100644 --- a/stubs/src/FunctionTemplate.php +++ b/stubs/src/FunctionTemplate.php @@ -84,8 +84,8 @@ * \code * FunctionTemplate Parent -> Parent() . prototype -> { } * ^ ^ - * | Inherit(Parent) | .__proto__ - * | | + * |Inherit(Parent) |.__proto__ + * | | * FunctionTemplate Child -> Child() . prototype -> { } * \endcode * @@ -172,7 +172,7 @@ public function setLength(int $length): void /** * Get the InstanceTemplate. * - * @return \V8\ObjectTemplate + * @return ObjectTemplate */ public function instanceTemplate(): ObjectTemplate { @@ -193,7 +193,7 @@ public function inherit(FunctionTemplate $parent) * A PrototypeTemplate is the template used to create the prototype object * of the function created by this template. * - * @return \V8\ObjectTemplate + * @return ObjectTemplate */ public function prototypeTemplate(): ObjectTemplate { diff --git a/stubs/src/IndexFilter.php b/stubs/src/IndexFilter.php index 4ee7c9d..1188fae 100644 --- a/stubs/src/IndexFilter.php +++ b/stubs/src/IndexFilter.php @@ -18,5 +18,5 @@ class IndexFilter { const kIncludeIndices = 0; // allows for integer indices to be collected, while - const kSkipIndices = 1; // will exclude integer indicies from being collected. + const kSkipIndices = 1; // will exclude integer indicies from being collected. } diff --git a/stubs/src/Isolate.php b/stubs/src/Isolate.php index 394cdb2..a6988bf 100644 --- a/stubs/src/Isolate.php +++ b/stubs/src/Isolate.php @@ -88,7 +88,7 @@ public function inContext(): bool /** * Returns the last entered context. * - * @return \V8\Context + * @return Context */ public function getEnteredContext(): Context { diff --git a/stubs/src/KeyCollectionMode.php b/stubs/src/KeyCollectionMode.php index 66ffa63..9ca9a36 100644 --- a/stubs/src/KeyCollectionMode.php +++ b/stubs/src/KeyCollectionMode.php @@ -20,6 +20,6 @@ */ class KeyCollectionMode { - const kOwnOnly = 0; // limits the collected properties to the given Object only. kIncludesPrototypes + const kOwnOnly = 0; // limits the collected properties to the given Object only. kIncludesPrototypes const kIncludesPrototypes = 1; // will include all keys of the objects's prototype chain as well. } diff --git a/stubs/src/MapObject.php b/stubs/src/MapObject.php index 0df265f..0f858e4 100644 --- a/stubs/src/MapObject.php +++ b/stubs/src/MapObject.php @@ -33,7 +33,7 @@ public function clear() * @param Context $context * @param Value $key * - * @return Value + * @return Value|PrimitiveValue|ObjectValue */ public function get(Context $context, Value $key): Value { diff --git a/stubs/src/ObjectTemplate.php b/stubs/src/ObjectTemplate.php index 1be45c8..9266844 100644 --- a/stubs/src/ObjectTemplate.php +++ b/stubs/src/ObjectTemplate.php @@ -33,7 +33,7 @@ public function __construct(Isolate $isolate, FunctionTemplate $constructor = nu * * @param Context $context * - * @return \V8\ObjectValue + * @return ObjectValue */ public function newInstance(Context $context): ObjectValue { @@ -85,9 +85,9 @@ public function setAccessor( * invoked instead of accessing the property directly on the JavaScript * object. * - * See \V8\NamedPropertyHandlerConfiguration constructor argument description for details + * See NamedPropertyHandlerConfiguration constructor argument description for details * - * @param \V8\NamedPropertyHandlerConfiguration The NamedPropertyHandlerConfiguration that defines the callbacks to invoke when accessing a property. + * @param NamedPropertyHandlerConfiguration The NamedPropertyHandlerConfiguration that defines the callbacks to invoke when accessing a property. */ public function setHandlerForNamedProperty(NamedPropertyHandlerConfiguration $configuration) { @@ -100,9 +100,9 @@ public function setHandlerForNamedProperty(NamedPropertyHandlerConfiguration $co * this object template, the provided callback is invoked instead of * accessing the property directly on the JavaScript object. * - * See \V8\IndexedPropertyHandlerConfiguration constructor argument description for details + * See IndexedPropertyHandlerConfiguration constructor argument description for details * - * @param \V8\IndexedPropertyHandlerConfiguration $configuration The IndexedPropertyHandlerConfiguration that defines the callbacks to invoke when accessing a property. + * @param IndexedPropertyHandlerConfiguration $configuration The IndexedPropertyHandlerConfiguration that defines the callbacks to invoke when accessing a property. */ public function setHandlerForIndexedProperty(IndexedPropertyHandlerConfiguration $configuration) { diff --git a/stubs/src/ObjectValue.php b/stubs/src/ObjectValue.php index 6fbf1fb..c060d7f 100644 --- a/stubs/src/ObjectValue.php +++ b/stubs/src/ObjectValue.php @@ -27,7 +27,7 @@ public function __construct(Context $context) } /** - * @return \V8\Context + * @return Context */ public function getContext() { @@ -86,7 +86,7 @@ public function defineOwnProperty( * @param Context $context * @param Value $key * - * @return \V8\Value | \V8\ObjectValue | \V8\FunctionObject | ArrayObject | StringValue | NumberValue + * @return Value|PrimitiveValue|ObjectValue */ public function get(Context $context, Value $key): Value { @@ -112,7 +112,7 @@ public function getPropertyAttributes(Context $context, NameValue $key): int * @param Context $context * @param NameValue $key * - * @return \V8\Value + * @return Value|PrimitiveValue|ObjectValue */ public function getOwnPropertyDescriptor(Context $context, NameValue $key): Value { @@ -235,7 +235,7 @@ public function getOwnPropertyNames(Context $context, int $filter = PropertyFilt * be skipped by __proto__ and it does not consult the security * handler. * - * @return \V8\Value + * @return Value */ public function getPrototype(): Value { @@ -293,7 +293,7 @@ public function getConstructorName(): StringValue * Sets the integrity level of the object. * * @param Context $context - * @param int $level One of \V8\IntegrityLevel::{kFrozen, kSealed} + * @param int $level One of IntegrityLevel::{kFrozen, kSealed} * * @return bool */ @@ -348,7 +348,7 @@ public function hasRealNamedCallbackProperty(Context $context, $key): bool * @param Context $context * @param string $key * - * @return \V8\Value + * @return Value */ public function getRealNamedPropertyInPrototypeChain(Context $context, $key): Value { @@ -376,7 +376,7 @@ public function getRealNamedPropertyAttributesInPrototypeChain(Context $context, * @param Context $context * @param string $key * - * @return \V8\Value + * @return Value */ public function getRealNamedProperty(Context $context, $key): Value { @@ -466,7 +466,7 @@ public function isConstructor(): bool * @param Value $recv * @param array $arguments * - * @return \V8\Value + * @return Value|PrimitiveValue|ObjectValue */ public function callAsFunction(Context $context, Value $recv, array $arguments = []): Value { @@ -480,7 +480,7 @@ public function callAsFunction(Context $context, Value $recv, array $arguments = * @param Context $context * @param array $arguments * - * @return \V8\Value + * @return Value|PrimitiveValue|ObjectValue */ public function callAsConstructor(Context $context, array $arguments = []): Value { diff --git a/stubs/src/PromiseObject.php b/stubs/src/PromiseObject.php index 8b126c5..d74eaf0 100644 --- a/stubs/src/PromiseObject.php +++ b/stubs/src/PromiseObject.php @@ -94,7 +94,7 @@ public function hasHandler(): bool /** * Returns the content of the promise result (resolve or reject value). The Promise must not be pending. * - * @return Value + * @return Value|PrimitiveValue|ObjectValue */ public function result(): Value { diff --git a/stubs/src/ProxyObject.php b/stubs/src/ProxyObject.php index 533f4cc..f0f2872 100644 --- a/stubs/src/ProxyObject.php +++ b/stubs/src/ProxyObject.php @@ -35,7 +35,7 @@ public function getTarget(): ObjectValue } /** - * @return Value + * @return Value|ObjectValue|NullValue */ public function getHandler(): Value { diff --git a/stubs/src/ReturnValue.php b/stubs/src/ReturnValue.php index 47ec00c..5750fb3 100644 --- a/stubs/src/ReturnValue.php +++ b/stubs/src/ReturnValue.php @@ -20,14 +20,14 @@ class ReturnValue { /** - * @return \V8\Isolate + * @return Isolate */ public function getIsolate(): Isolate { } /** - * @return \V8\Context + * @return Context */ public function getContext(): Context { @@ -43,7 +43,7 @@ public function inContext(): bool } /** - * @param \V8\Value $value + * @param Value $value */ public function set(Value $value) { @@ -54,7 +54,7 @@ public function set(Value $value) * * If the ReturnValue was not yet set, this will return the undefined value. * - * @return Value|StringValue|NumberValue|ObjectValue|ArrayObject|FunctionObject|DateObject|RegExpObject + * @return Value|PrimitiveValue|ObjectValue */ public function get(): Value { diff --git a/stubs/src/Script.php b/stubs/src/Script.php index 1c92786..d1c4a56 100644 --- a/stubs/src/Script.php +++ b/stubs/src/Script.php @@ -39,7 +39,7 @@ public function getIsolate(): Isolate } /** - * @return \V8\Context + * @return Context */ public function getContext(): Context { @@ -48,9 +48,9 @@ public function getContext(): Context /** * Runs the script returning the resulting value. * - * @param \V8\Context $context + * @param Context $context * - * @return BooleanValue | FunctionObject | NumberValue | ObjectValue | StringValue | Value + * @return Value|PrimitiveValue|ObjectValue */ public function run(Context $context): Value { @@ -59,7 +59,7 @@ public function run(Context $context): Value /** * Returns the corresponding context-unbound script. * - * @return \V8\UnboundScript + * @return UnboundScript */ public function getUnboundScript(): UnboundScript { diff --git a/stubs/src/SetObject.php b/stubs/src/SetObject.php index 054c9b4..ab12a58 100644 --- a/stubs/src/SetObject.php +++ b/stubs/src/SetObject.php @@ -43,7 +43,7 @@ public function delete(Context $context, Value $key): bool /** * Returns an array of the keys in this Set. * - * @return \V8\ArrayObject + * @return ArrayObject */ public function asArray(): ArrayObject { diff --git a/stubs/src/StackTrace.php b/stubs/src/StackTrace.php index 414c344..afd4800 100644 --- a/stubs/src/StackTrace.php +++ b/stubs/src/StackTrace.php @@ -39,7 +39,7 @@ class StackTrace */ public function __construct(array $frames) { - $this->frames = $frames; + $this->frames = $frames; } diff --git a/stubs/src/StringObject.php b/stubs/src/StringObject.php index 38cd75b..a12963c 100644 --- a/stubs/src/StringObject.php +++ b/stubs/src/StringObject.php @@ -22,8 +22,8 @@ class StringObject extends ObjectValue { /** - * @param \V8\Context $context - * @param \V8\StringValue $value + * @param Context $context + * @param StringValue $value */ public function __construct(Context $context, StringValue $value) { @@ -31,7 +31,7 @@ public function __construct(Context $context, StringValue $value) } /** - * @return \V8\StringValue + * @return StringValue */ public function valueOf(): StringValue { diff --git a/stubs/src/StringValue.php b/stubs/src/StringValue.php index 4d966c1..11fb641 100644 --- a/stubs/src/StringValue.php +++ b/stubs/src/StringValue.php @@ -62,7 +62,7 @@ public function isOneByte(): bool /** * @return bool */ - public function containsOnlyOneByte():bool + public function containsOnlyOneByte(): bool { } } diff --git a/stubs/src/SymbolValue.php b/stubs/src/SymbolValue.php index 645f091..49a9ca8 100644 --- a/stubs/src/SymbolValue.php +++ b/stubs/src/SymbolValue.php @@ -43,7 +43,7 @@ public function value(): string /** * Returns the print name string of the symbol, or undefined if none. * - * @return StringValue | UndefinedValue | Value + * @return Value|StringValue|UndefinedValue */ public function name(): Value { @@ -96,7 +96,7 @@ public static function getHasInstance(Isolate $isolate): SymbolValue /** * @param Isolate $isolate * - * @return \V8\SymbolValue + * @return SymbolValue */ public static function getIsConcatSpreadable(Isolate $isolate): SymbolValue { diff --git a/stubs/src/Template.php b/stubs/src/Template.php index 8ea4b35..0bc6770 100644 --- a/stubs/src/Template.php +++ b/stubs/src/Template.php @@ -19,20 +19,20 @@ class Template extends Data { /** - * @var \V8\Isolate + * @var Isolate */ private $isolate; /** * @param Isolate $isolate */ - public function __construct(\V8\Isolate $isolate) + public function __construct(Isolate $isolate) { $this->isolate = $isolate; } /** - * @return \V8\Isolate + * @return Isolate */ public function getIsolate(): Isolate { @@ -44,7 +44,7 @@ public function getIsolate(): Isolate * * @param NameValue $name * @param Data|PrimitiveValue|Template $value - * @param int $attributes One of \V8\PropertyAttribute constants + * @param int $attributes One of PropertyAttribute constants * * @return void */ @@ -53,11 +53,11 @@ public function set(NameValue $name, Data $value, int $attributes = PropertyAttr } /** - * @param NameValue $name - * @param \V8\FunctionTemplate $getter - * @param \V8\FunctionTemplate $setter - * @param int $attribute - * @param int $settings + * @param NameValue $name + * @param FunctionTemplate $getter + * @param FunctionTemplate $setter + * @param int $attribute + * @param int $settings * * @return void */ @@ -92,7 +92,7 @@ public function setAccessorProperty( * defined by FunctionTemplate::HasInstance()), an implicit TypeError is * thrown and no callback is invoked. * - * @param int $settings Access control settings for the accessor. + * @param int $settings Access control settings for the accessor. * * @return void */ diff --git a/stubs/src/TryCatch.php b/stubs/src/TryCatch.php index e296b06..a7c4898 100644 --- a/stubs/src/TryCatch.php +++ b/stubs/src/TryCatch.php @@ -60,13 +60,13 @@ class TryCatch * all TryCatch blocks should be stack allocated because the memory * location itself is compared against JavaScript try/catch blocks. * - * @param Isolate $isolate - * @param Context $context - * @param Value $exception - * @param Value $stack_trace - * @param Message $message - * @param bool $can_continue - * @param bool $has_terminated + * @param Isolate $isolate + * @param Context $context + * @param Value $exception + * @param Value $stack_trace + * @param Message $message + * @param bool $can_continue + * @param bool $has_terminated * @param Throwable|null $external_exception */ public function __construct( @@ -79,17 +79,17 @@ public function __construct( bool $has_terminated = false, Throwable $external_exception = null ) { - $this->isolate = $isolate; - $this->exception = $exception; - $this->stack_trace = $stack_trace; - $this->message = $message; - $this->can_continue = $can_continue; - $this->has_terminated = $has_terminated; + $this->isolate = $isolate; + $this->exception = $exception; + $this->stack_trace = $stack_trace; + $this->message = $message; + $this->can_continue = $can_continue; + $this->has_terminated = $has_terminated; $this->external_exception = $external_exception; } /** - * @return \V8\Isolate + * @return Isolate */ public function getIsolate(): Isolate { @@ -97,7 +97,7 @@ public function getIsolate(): Isolate } /** - * @return \V8\Context + * @return Context */ public function getContext(): Context { @@ -110,7 +110,7 @@ public function getContext(): Context * * The returned handle is valid until this TryCatch block has been destroyed. * - * @return \V8\Value|null + * @return Value|null * */ public function exception(): ?Value @@ -122,7 +122,7 @@ public function exception(): ?Value * Returns the .stack property of the thrown object. If no .stack * property is present an empty handle is returned. * - * @return \V8\Value|null + * @return Value|null */ public function stackTrace(): ?Value { diff --git a/stubs/src/UnboundScript.php b/stubs/src/UnboundScript.php index 9775a39..ebd1292 100644 --- a/stubs/src/UnboundScript.php +++ b/stubs/src/UnboundScript.php @@ -33,7 +33,7 @@ public function getId(): int } /** - * @return Value + * @return Value|PrimitiveValue|ObjectValue */ public function getScriptName(): Value { @@ -42,7 +42,7 @@ public function getScriptName(): Value /** * Data read from magic sourceURL comments. * - * @return Value + * @return Value|PrimitiveValue|ObjectValue */ public function getSourceURL(): Value { @@ -51,7 +51,7 @@ public function getSourceURL(): Value /** * Data read from magic sourceMappingURL comments. * - * @return Value + * @return Value|PrimitiveValue|ObjectValue */ public function getSourceMappingURL(): Value { diff --git a/stubs/src/Value.php b/stubs/src/Value.php index 383c6c8..3d93dd9 100644 --- a/stubs/src/Value.php +++ b/stubs/src/Value.php @@ -22,7 +22,7 @@ abstract class Value extends Data { /** - * @return \V8\Isolate + * @return Isolate */ public function getIsolate(): Isolate { @@ -454,7 +454,7 @@ public function isProxy(): bool /** * @param Context $context * - * @return \V8\BooleanValue + * @return BooleanValue */ public function toBoolean(Context $context): BooleanValue { @@ -463,7 +463,7 @@ public function toBoolean(Context $context): BooleanValue /** * @param Context $context * - * @return \V8\NumberValue + * @return NumberValue */ public function toNumber(Context $context): NumberValue { @@ -472,7 +472,7 @@ public function toNumber(Context $context): NumberValue /** * @param Context $context * - * @return \V8\StringValue + * @return StringValue */ public function toString(Context $context): StringValue { @@ -481,7 +481,7 @@ public function toString(Context $context): StringValue /** * @param Context $context * - * @return \V8\StringValue + * @return StringValue */ public function toDetailString(Context $context): StringValue { @@ -491,7 +491,7 @@ public function toDetailString(Context $context): StringValue * * @param Context $context * - * @return \V8\ObjectValue + * @return ObjectValue */ public function toObject(Context $context): ObjectValue { @@ -501,7 +501,7 @@ public function toObject(Context $context): ObjectValue * * @param Context $context * - * @return \V8\IntegerValue + * @return IntegerValue */ public function toInteger(Context $context): IntegerValue { @@ -511,7 +511,7 @@ public function toInteger(Context $context): IntegerValue * * @param Context $context * - * @return \V8\Uint32Value + * @return Uint32Value */ public function toUint32(Context $context): Uint32Value { @@ -520,7 +520,7 @@ public function toUint32(Context $context): Uint32Value /** * @param Context $context * - * @return \V8\Int32Value + * @return Int32Value */ public function toInt32(Context $context): Int32Value { @@ -532,7 +532,7 @@ public function toInt32(Context $context): Int32Value * * @param Context $context * - * @return \V8\Uint32Value + * @return Uint32Value */ public function toArrayIndex(Context $context) { From f4a84c556307ddfbb7d466e6cc64fe9a67727cae Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sat, 16 Sep 2017 23:20:27 +0300 Subject: [PATCH 05/17] Enforce strict_type in stubs [skip ci] --- stubs/src/AccessControl.php | 2 +- stubs/src/AdjustableExternalMemoryInterface.php | 2 +- stubs/src/ArrayObject.php | 2 +- stubs/src/BooleanObject.php | 2 +- stubs/src/BooleanValue.php | 2 +- stubs/src/CallbackInfo.php | 2 +- stubs/src/ConstructorBehavior.php | 2 +- stubs/src/Context.php | 2 +- stubs/src/Data.php | 2 +- stubs/src/DateObject.php | 2 +- stubs/src/ExceptionManager.php | 2 +- stubs/src/Exceptions/Exception.php | 2 +- stubs/src/Exceptions/MemoryLimitException.php | 2 +- stubs/src/Exceptions/ResourceLimitException.php | 2 +- stubs/src/Exceptions/TerminationException.php | 2 +- stubs/src/Exceptions/TimeLimitException.php | 2 +- stubs/src/Exceptions/TryCatchException.php | 2 +- stubs/src/Exceptions/ValueException.php | 2 +- stubs/src/FunctionCallbackInfo.php | 2 +- stubs/src/FunctionObject.php | 2 +- stubs/src/FunctionTemplate.php | 2 +- stubs/src/HeapStatistics.php | 2 +- stubs/src/IndexFilter.php | 2 +- stubs/src/IndexedPropertyHandlerConfiguration.php | 2 +- stubs/src/Int32Value.php | 2 +- stubs/src/IntegerValue.php | 2 +- stubs/src/IntegrityLevel.php | 2 +- stubs/src/Isolate.php | 2 +- stubs/src/KeyCollectionMode.php | 2 +- stubs/src/MapObject.php | 2 +- stubs/src/Message.php | 2 +- stubs/src/NameValue.php | 2 +- stubs/src/NamedPropertyHandlerConfiguration.php | 2 +- stubs/src/NullValue.php | 2 +- stubs/src/NumberObject.php | 2 +- stubs/src/NumberValue.php | 2 +- stubs/src/ObjectTemplate.php | 2 +- stubs/src/ObjectValue.php | 2 +- stubs/src/PrimitiveValue.php | 2 +- stubs/src/PromiseObject.php | 2 +- stubs/src/PropertyAttribute.php | 2 +- stubs/src/PropertyCallbackInfo.php | 2 +- stubs/src/PropertyFilter.php | 2 +- stubs/src/PropertyHandlerFlags.php | 2 +- stubs/src/ProxyObject.php | 2 +- stubs/src/RegExpObject.php | 2 +- stubs/src/ReturnValue.php | 2 +- stubs/src/Script.php | 2 +- stubs/src/ScriptCompiler.php | 2 +- stubs/src/ScriptCompiler/CachedData.php | 2 +- stubs/src/ScriptCompiler/CompileOptions.php | 2 +- stubs/src/ScriptCompiler/Source.php | 2 +- stubs/src/ScriptOrigin.php | 2 +- stubs/src/ScriptOriginOptions.php | 2 +- stubs/src/SetObject.php | 2 +- stubs/src/StackFrame.php | 2 +- stubs/src/StackTrace.php | 2 +- stubs/src/StartupData.php | 2 +- stubs/src/StringObject.php | 2 +- stubs/src/StringValue.php | 2 +- stubs/src/SymbolObject.php | 2 +- stubs/src/SymbolValue.php | 2 +- stubs/src/Template.php | 2 +- stubs/src/TryCatch.php | 2 +- stubs/src/Uint32Value.php | 2 +- stubs/src/UnboundScript.php | 2 +- stubs/src/UndefinedValue.php | 2 +- stubs/src/Value.php | 2 +- 68 files changed, 68 insertions(+), 68 deletions(-) diff --git a/stubs/src/AccessControl.php b/stubs/src/AccessControl.php index 7632d4b..47c200a 100644 --- a/stubs/src/AccessControl.php +++ b/stubs/src/AccessControl.php @@ -1,4 +1,4 @@ - Date: Sat, 16 Sep 2017 23:23:56 +0300 Subject: [PATCH 06/17] Add StackFrame::isWasm(), closes #53 --- src/php_v8_stack_frame.cc | 26 +++++++++++++-- stubs/src/StackFrame.php | 33 +++++++++---------- tests/001-verify_extension_entities.phpt | 4 ++- .../ExceptionManager_createGetStackTrace.phpt | 4 ++- tests/StackFrame.phpt | 14 ++++++-- tests/StackTrace.phpt | 8 +++-- 6 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/php_v8_stack_frame.cc b/src/php_v8_stack_frame.cc index f94ad40..095a9ad 100644 --- a/src/php_v8_stack_frame.cc +++ b/src/php_v8_stack_frame.cc @@ -60,6 +60,9 @@ void php_v8_stack_frame_create_from_stack_frame(v8::Isolate *isolate, zval *retu /* v8::StackFrame::IsConstructor */ zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_constructor"), static_cast(frame->IsConstructor())); + + /* v8::StackFrame::IsWasm */ + zend_update_property_bool(this_ce, return_value, ZEND_STRL("is_wasm"), static_cast(frame->IsWasm())); } static PHP_METHOD(StackFrame, __construct) { @@ -73,11 +76,12 @@ static PHP_METHOD(StackFrame, __construct) { zend_bool is_eval = '\0'; zend_bool is_constructor = '\0'; + zend_bool is_wasm = '\0'; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lllSSSbb", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lllSSSbbb", &line_number, &column, &script_id, &script_name, &script_name_or_source_url, &function_name, - &is_eval, &is_constructor) == FAILURE) { + &is_eval, &is_constructor, &is_wasm) == FAILURE) { return; } @@ -105,6 +109,7 @@ static PHP_METHOD(StackFrame, __construct) { zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_eval"), is_eval); zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_constructor"), is_constructor); + zend_update_property_bool(this_ce, getThis(), ZEND_STRL("is_wasm"), is_wasm); } static PHP_METHOD(StackFrame, getLineNumber) { @@ -187,6 +192,17 @@ static PHP_METHOD(StackFrame, isConstructor) { RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("is_constructor"), 0, &rv), 1, 0); } +static PHP_METHOD(StackFrame, isWasm) { + zval rv; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("is_wasm"), 0, &rv), 1, 0); +} + + PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 0) ZEND_ARG_TYPE_INFO(0, line_number, IS_LONG, 1) ZEND_ARG_TYPE_INFO(0, column, IS_LONG, 1) @@ -196,6 +212,7 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 0) ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, is_eval, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO(0, is_constructor, _IS_BOOL, 0) + ZEND_ARG_TYPE_INFO(0, is_wasm, _IS_BOOL, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getLineNumber, ZEND_RETURN_VALUE, 0, IS_LONG, 1) @@ -222,6 +239,9 @@ ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_isConstructor, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_isWasm, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + static const zend_function_entry php_v8_stack_frame_methods[] = { PHP_V8_ME(StackFrame, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) @@ -233,6 +253,7 @@ static const zend_function_entry php_v8_stack_frame_methods[] = { PHP_V8_ME(StackFrame, getFunctionName, ZEND_ACC_PUBLIC) PHP_V8_ME(StackFrame, isEval, ZEND_ACC_PUBLIC) PHP_V8_ME(StackFrame, isConstructor, ZEND_ACC_PUBLIC) + PHP_V8_ME(StackFrame, isWasm, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -253,6 +274,7 @@ PHP_MINIT_FUNCTION (php_v8_stack_frame) { zend_declare_property_bool(this_ce, ZEND_STRL("is_eval"), static_cast(false), ZEND_ACC_PRIVATE); zend_declare_property_bool(this_ce, ZEND_STRL("is_constructor"), static_cast(false), ZEND_ACC_PRIVATE); + zend_declare_property_bool(this_ce, ZEND_STRL("is_wasm"), static_cast(false), ZEND_ACC_PRIVATE); return SUCCESS; } diff --git a/stubs/src/StackFrame.php b/stubs/src/StackFrame.php index 8620089..9d4d846 100644 --- a/stubs/src/StackFrame.php +++ b/stubs/src/StackFrame.php @@ -52,6 +52,10 @@ class StackFrame * @var bool */ private $is_constructor; + /** + * @var bool + */ + private $is_wasm; /** * @param int|null $line_number @@ -62,6 +66,7 @@ class StackFrame * @param string $function_name * @param bool $is_eval * @param bool $is_constructor + * @param bool $is_wasm */ public function __construct( ?int $line_number = null, @@ -71,16 +76,9 @@ public function __construct( string $script_name_or_source_url = '', string $function_name = '', bool $is_eval = false, - bool $is_constructor = false + bool $is_constructor = false, + bool $is_wasm = false ) { - $this->line_number = $line_number; - $this->column = $column; - $this->script_id = $script_id; - $this->script_name = $script_name; - $this->script_name_or_source_url = $script_name_or_source_url; - $this->function_name = $function_name; - $this->is_eval = $is_eval; - $this->is_constructor = $is_constructor; } /** @@ -93,7 +91,6 @@ public function __construct( */ public function getLineNumber(): ?int { - return $this->line_number; } /** @@ -107,7 +104,6 @@ public function getLineNumber(): ?int */ public function getColumn(): ?int { - return $this->column; } /** @@ -120,7 +116,6 @@ public function getColumn(): ?int */ public function getScriptId(): ?int { - return $this->script_id; } /** @@ -131,7 +126,6 @@ public function getScriptId(): ?int */ public function getScriptName(): string { - return $this->script_name; } /** @@ -144,7 +138,6 @@ public function getScriptName(): string */ public function getScriptNameOrSourceURL(): string { - return $this->script_name_or_source_url; } /** @@ -154,7 +147,6 @@ public function getScriptNameOrSourceURL(): string */ public function getFunctionName(): string { - return $this->function_name; } /** @@ -165,7 +157,6 @@ public function getFunctionName(): string */ public function isEval(): bool { - return $this->is_eval; } /** @@ -176,6 +167,14 @@ public function isEval(): bool */ public function isConstructor(): bool { - return $this->is_constructor; + } + + /** + * Returns whether or not the associated functions is defined in wasm. + * + * @return bool + */ + public function isWasm(): bool + { } } diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index ff1e52b..7d05cf5 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -470,7 +470,8 @@ class V8\StackFrame private $function_name private $is_eval private $is_constructor - public function __construct(?int $line_number, ?int $column, ?int $script_id, string $script_name, string $script_name_or_source_url, string $function_name, bool $is_eval, bool $is_constructor) + private $is_wasm + public function __construct(?int $line_number, ?int $column, ?int $script_id, string $script_name, string $script_name_or_source_url, string $function_name, bool $is_eval, bool $is_constructor, bool $is_wasm) public function getLineNumber(): ?int public function getColumn(): ?int public function getScriptId(): ?int @@ -479,6 +480,7 @@ class V8\StackFrame public function getFunctionName(): string public function isEval(): bool public function isConstructor(): bool + public function isWasm(): bool class V8\StackTrace const MIN_FRAME_LIMIT = 0 diff --git a/tests/ExceptionManager_createGetStackTrace.phpt b/tests/ExceptionManager_createGetStackTrace.phpt index 1027fd8..b851d32 100644 --- a/tests/ExceptionManager_createGetStackTrace.phpt +++ b/tests/ExceptionManager_createGetStackTrace.phpt @@ -116,7 +116,7 @@ Stack trace created from thrown value: V8\StackTrace->getFrames(): array(1) { [0]=> - object(V8\StackFrame)#14 (8) { + object(V8\StackFrame)#14 (9) { ["line_number":"V8\StackFrame":private]=> int(5) ["column":"V8\StackFrame":private]=> @@ -133,6 +133,8 @@ V8\StackTrace->getFrames(): bool(false) ["is_constructor":"V8\StackFrame":private]=> bool(false) + ["is_wasm":"V8\StackFrame":private]=> + bool(false) } } V8\StackTrace->getFrameCount(): int(1) diff --git a/tests/StackFrame.phpt b/tests/StackFrame.phpt index c2ae1e0..74d0c25 100644 --- a/tests/StackFrame.phpt +++ b/tests/StackFrame.phpt @@ -25,10 +25,11 @@ $helper->method_matches_with_output($obj, 'getScriptNameOrSourceURL', ''); $helper->method_matches_with_output($obj, 'getFunctionName', ''); $helper->method_matches_with_output($obj, 'isEval', false); $helper->method_matches_with_output($obj, 'isConstructor', false); +$helper->method_matches_with_output($obj, 'isWasm', false); $helper->space(); -$obj = new V8\StackFrame(1, 2, 3, 'script_name', 'script_name_or_source_url', 'function_name', true, true); +$obj = new V8\StackFrame(1, 2, 3, 'script_name', 'script_name_or_source_url', 'function_name', true, true, true); $helper->header('Object representation'); @@ -44,13 +45,14 @@ $helper->method_matches_with_output($obj, 'getScriptNameOrSourceURL', 'script_na $helper->method_matches_with_output($obj, 'getFunctionName', 'function_name'); $helper->method_matches_with_output($obj, 'isEval', true); $helper->method_matches_with_output($obj, 'isConstructor', true); +$helper->method_matches_with_output($obj, 'isWasm', true); $helper->space(); ?> --EXPECT-- Object representation (default): -------------------------------- -object(V8\StackFrame)#2 (8) { +object(V8\StackFrame)#2 (9) { ["line_number":"V8\StackFrame":private]=> NULL ["column":"V8\StackFrame":private]=> @@ -67,6 +69,8 @@ object(V8\StackFrame)#2 (8) { bool(false) ["is_constructor":"V8\StackFrame":private]=> bool(false) + ["is_wasm":"V8\StackFrame":private]=> + bool(false) } @@ -80,11 +84,12 @@ V8\StackFrame::getScriptNameOrSourceURL() matches expected '' V8\StackFrame::getFunctionName() matches expected '' V8\StackFrame::isEval() matches expected false V8\StackFrame::isConstructor() matches expected false +V8\StackFrame::isWasm() matches expected false Object representation: ---------------------- -object(V8\StackFrame)#3 (8) { +object(V8\StackFrame)#3 (9) { ["line_number":"V8\StackFrame":private]=> int(1) ["column":"V8\StackFrame":private]=> @@ -101,6 +106,8 @@ object(V8\StackFrame)#3 (8) { bool(true) ["is_constructor":"V8\StackFrame":private]=> bool(true) + ["is_wasm":"V8\StackFrame":private]=> + bool(true) } @@ -114,3 +121,4 @@ V8\StackFrame::getScriptNameOrSourceURL() matches expected 'script_name_or_sourc V8\StackFrame::getFunctionName() matches expected 'function_name' V8\StackFrame::isEval() matches expected true V8\StackFrame::isConstructor() matches expected true +V8\StackFrame::isWasm() matches expected true diff --git a/tests/StackTrace.phpt b/tests/StackTrace.phpt index 1d193c9..236a010 100644 --- a/tests/StackTrace.phpt +++ b/tests/StackTrace.phpt @@ -54,7 +54,7 @@ object(V8\StackTrace)#7 (1) { ["frames":"V8\StackTrace":private]=> array(2) { [0]=> - object(V8\StackFrame)#5 (8) { + object(V8\StackFrame)#5 (9) { ["line_number":"V8\StackFrame":private]=> int(1) ["column":"V8\StackFrame":private]=> @@ -71,9 +71,11 @@ object(V8\StackTrace)#7 (1) { bool(false) ["is_constructor":"V8\StackFrame":private]=> bool(false) + ["is_wasm":"V8\StackFrame":private]=> + bool(false) } [1]=> - object(V8\StackFrame)#6 (8) { + object(V8\StackFrame)#6 (9) { ["line_number":"V8\StackFrame":private]=> int(2) ["column":"V8\StackFrame":private]=> @@ -90,6 +92,8 @@ object(V8\StackTrace)#7 (1) { bool(false) ["is_constructor":"V8\StackFrame":private]=> bool(false) + ["is_wasm":"V8\StackFrame":private]=> + bool(false) } } } From 31a99bf35416b6ddad7cc4d41f1bf0ece1a87a4f Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 13:13:53 +0300 Subject: [PATCH 07/17] Add missed parameter type hint --- src/php_v8_object.cc | 16 +++++------ stubs/src/ObjectValue.php | 35 ++++++++++++------------ tests/001-verify_extension_entities.phpt | 16 +++++------ 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/php_v8_object.cc b/src/php_v8_object.cc index c7125c2..8b652a0 100644 --- a/src/php_v8_object.cc +++ b/src/php_v8_object.cc @@ -1405,42 +1405,42 @@ ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hasOwnProperty, ZEND_RETURN_VALUE, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hasRealNamedProperty, ZEND_RETURN_VALUE, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hasRealIndexedProperty, ZEND_RETURN_VALUE, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, index) + ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hasRealNamedCallbackProperty, ZEND_RETURN_VALUE, 2, _IS_BOOL, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getRealNamedPropertyInPrototypeChain, ZEND_RETURN_VALUE, 2, V8\\Value, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getRealNamedPropertyAttributesInPrototypeChain, ZEND_RETURN_VALUE, 2, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getRealNamedProperty, ZEND_RETURN_VALUE, 2, V8\\Value, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getRealNamedPropertyAttributes, ZEND_RETURN_VALUE, 2, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) - ZEND_ARG_INFO(0, key) + ZEND_ARG_OBJ_INFO(0, key, V8\\NameValue, 0) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hasNamedLookupInterceptor, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) diff --git a/stubs/src/ObjectValue.php b/stubs/src/ObjectValue.php index 8ed34ed..cabd35c 100644 --- a/stubs/src/ObjectValue.php +++ b/stubs/src/ObjectValue.php @@ -302,42 +302,43 @@ public function setIntegrityLevel(Context $context, int $level): bool } /** - * @param Context $context - * @param string $key + * @param Context $context + * @param NameValue $key * * @return bool */ - public function hasOwnProperty(Context $context, $key): bool + public function hasOwnProperty(Context $context, NameValue $key): bool { } /** - * @param Context $context - * @param string $key + * @param Context $context + * + * @param NameValue $key * * @return bool */ - public function hasRealNamedProperty(Context $context, $key): bool + public function hasRealNamedProperty(Context $context, NameValue $key): bool { } /** * @param Context $context - * @param string $index + * @param int $index * * @return bool */ - public function hasRealIndexedProperty(Context $context, $index): bool + public function hasRealIndexedProperty(Context $context, int $index): bool { } /** - * @param Context $context - * @param string $key + * @param Context $context + * @param NameValue $key * * @return bool */ - public function hasRealNamedCallbackProperty(Context $context, $key): bool + public function hasRealNamedCallbackProperty(Context $context, NameValue $key): bool { } @@ -345,12 +346,12 @@ public function hasRealNamedCallbackProperty(Context $context, $key): bool * If result.IsEmpty() no real property was located in the prototype chain. * This means interceptors in the prototype chain are not called. * - * @param Context $context - * @param string $key + * @param Context $context + * @param NameValue $key * * @return Value */ - public function getRealNamedPropertyInPrototypeChain(Context $context, $key): Value + public function getRealNamedPropertyInPrototypeChain(Context $context, NameValue $key): Value { } @@ -373,12 +374,12 @@ public function getRealNamedPropertyAttributesInPrototypeChain(Context $context, * in the prototype chain. * This means interceptors in the prototype chain are not called. * - * @param Context $context - * @param string $key + * @param Context $context + * @param NameValue $key * * @return Value */ - public function getRealNamedProperty(Context $context, $key): Value + public function getRealNamedProperty(Context $context, NameValue $key): Value { } diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index 7d05cf5..c601865 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -689,14 +689,14 @@ class V8\ObjectValue public function objectProtoToString(V8\Context $context): V8\StringValue public function getConstructorName(): V8\StringValue public function setIntegrityLevel(V8\Context $context, int $level): bool - public function hasOwnProperty(V8\Context $context, $key): bool - public function hasRealNamedProperty(V8\Context $context, $key): bool - public function hasRealIndexedProperty(V8\Context $context, $index): bool - public function hasRealNamedCallbackProperty(V8\Context $context, $key): bool - public function getRealNamedPropertyInPrototypeChain(V8\Context $context, $key): V8\Value - public function getRealNamedPropertyAttributesInPrototypeChain(V8\Context $context, $key): int - public function getRealNamedProperty(V8\Context $context, $key): V8\Value - public function getRealNamedPropertyAttributes(V8\Context $context, $key): int + public function hasOwnProperty(V8\Context $context, V8\NameValue $key): bool + public function hasRealNamedProperty(V8\Context $context, V8\NameValue $key): bool + public function hasRealIndexedProperty(V8\Context $context, int $index): bool + public function hasRealNamedCallbackProperty(V8\Context $context, V8\NameValue $key): bool + public function getRealNamedPropertyInPrototypeChain(V8\Context $context, V8\NameValue $key): V8\Value + public function getRealNamedPropertyAttributesInPrototypeChain(V8\Context $context, V8\NameValue $key): int + public function getRealNamedProperty(V8\Context $context, V8\NameValue $key): V8\Value + public function getRealNamedPropertyAttributes(V8\Context $context, V8\NameValue $key): int public function hasNamedLookupInterceptor(): bool public function hasIndexedLookupInterceptor(): bool public function getIdentityHash(): int From e5ac94041b50180d43061e5a5e39c1083e6bab61 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 13:49:25 +0300 Subject: [PATCH 08/17] Remove CallbackInfo, closes #67 --- config.m4 | 1 - src/php_v8_callback_info.cc | 128 ----------------------- src/php_v8_callback_info.h | 29 ----- src/php_v8_callbacks.cc | 1 - src/php_v8_function_callback_info.cc | 98 +++++++++++++++-- src/php_v8_function_callback_info.h | 1 - src/php_v8_property_callback_info.cc | 101 ++++++++++++++++-- src/php_v8_property_callback_info.h | 1 - stubs/src/CallbackInfo.php | 67 ------------ stubs/src/FunctionCallbackInfo.php | 50 ++++++++- stubs/src/PropertyCallbackInfo.php | 50 ++++++++- tests/001-verify_extension_entities.phpt | 18 ++-- tests/FunctionCallbackInfo.phpt | 20 ++-- tests/Isolate_isInUse.phpt | 2 +- tests/PropertyCallbackInfo.phpt | 10 +- v8.cc | 2 - 16 files changed, 311 insertions(+), 268 deletions(-) delete mode 100644 src/php_v8_callback_info.cc delete mode 100644 src/php_v8_callback_info.h delete mode 100644 stubs/src/CallbackInfo.php diff --git a/config.m4 b/config.m4 index a8650e6..04240ba 100644 --- a/config.m4 +++ b/config.m4 @@ -211,7 +211,6 @@ if test "$PHP_V8" != "no"; then src/php_v8_symbol_object.cc \ src/php_v8_template.cc \ src/php_v8_return_value.cc \ - src/php_v8_callback_info.cc \ src/php_v8_function_callback_info.cc \ src/php_v8_property_callback_info.cc \ src/php_v8_named_property_handler_configuration.cc \ diff --git a/src/php_v8_callback_info.cc b/src/php_v8_callback_info.cc deleted file mode 100644 index 6ffd112..0000000 --- a/src/php_v8_callback_info.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php_v8_callback_info.h" -#include "php_v8_return_value.h" -#include "php_v8_value.h" -#include "php_v8.h" - - -zend_class_entry *php_v8_callback_info_class_entry; -#define this_ce php_v8_callback_info_class_entry - -static zend_object_handlers php_v8_callback_info_object_handlers; - - -static PHP_METHOD(CallbackInfo, getIsolate) { - zval rv; - zval *tmp; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("isolate"), 0, &rv); - ZVAL_COPY(return_value, tmp); -} - -static PHP_METHOD(CallbackInfo, getContext) { - zval rv; - zval *tmp; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("context"), 0, &rv); - ZVAL_COPY(return_value, tmp); -} - -static PHP_METHOD(CallbackInfo, this) { - zval rv; - zval *tmp; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("this"), 0, &rv); - ZVAL_COPY(return_value, tmp); -} - -static PHP_METHOD(CallbackInfo, holder) { - zval rv; - zval *tmp; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("holder"), 0, &rv); - ZVAL_COPY(return_value, tmp); -} - -static PHP_METHOD(CallbackInfo, getReturnValue) { - zval rv; - zval *tmp; - - if (zend_parse_parameters_none() == FAILURE) { - return; - } - - tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("return_value"), 0, &rv); - ZVAL_COPY(return_value, tmp); -} - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIsolate, ZEND_RETURN_VALUE, 0, V8\\Isolate, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_this, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_holder, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0) -ZEND_END_ARG_INFO() - -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getReturnValue, ZEND_RETURN_VALUE, 0, V8\\ReturnValue, 0) -ZEND_END_ARG_INFO() - -static const zend_function_entry php_v8_callback_info_methods[] = { - PHP_V8_ME(CallbackInfo, this, ZEND_ACC_PUBLIC) - PHP_V8_ME(CallbackInfo, holder, ZEND_ACC_PUBLIC) - PHP_V8_ME(CallbackInfo, getIsolate, ZEND_ACC_PUBLIC) - PHP_V8_ME(CallbackInfo, getContext, ZEND_ACC_PUBLIC) - PHP_V8_ME(CallbackInfo, getReturnValue, ZEND_ACC_PUBLIC) - PHP_FE_END -}; - -PHP_MINIT_FUNCTION (php_v8_callback_info) { - zend_class_entry ce; - - INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "CallbackInfo", php_v8_callback_info_methods); - this_ce = zend_register_internal_class(&ce); - - memcpy(&php_v8_callback_info_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - - zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE); - zend_declare_property_null(this_ce, ZEND_STRL("context"), ZEND_ACC_PRIVATE); - zend_declare_property_null(this_ce, ZEND_STRL("this"), ZEND_ACC_PRIVATE); - zend_declare_property_null(this_ce, ZEND_STRL("holder"), ZEND_ACC_PRIVATE); - zend_declare_property_null(this_ce, ZEND_STRL("return_value"), ZEND_ACC_PRIVATE); - - return SUCCESS; -} diff --git a/src/php_v8_callback_info.h b/src/php_v8_callback_info.h deleted file mode 100644 index 492786a..0000000 --- a/src/php_v8_callback_info.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * This file is part of the pinepain/php-v8 PHP extension. - * - * Copyright (c) 2015-2017 Bogdan Padalko - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - -#ifndef PHP_V8_CALLBACK_INFO_H -#define PHP_V8_CALLBACK_INFO_H - -extern "C" { -#include "php.h" - -#ifdef ZTS -#include "TSRM.h" -#endif -} - -extern zend_class_entry* php_v8_callback_info_class_entry; - - -PHP_MINIT_FUNCTION(php_v8_callback_info); - -#endif //PHP_V8_CALLBACK_INFO_H diff --git a/src/php_v8_callbacks.cc b/src/php_v8_callbacks.cc index fa1331d..4a7b3f1 100644 --- a/src/php_v8_callbacks.cc +++ b/src/php_v8_callbacks.cc @@ -15,7 +15,6 @@ #endif #include "php_v8_callbacks.h" -#include "php_v8_callback_info.h" #include "php_v8_property_callback_info.h" #include "php_v8_function_callback_info.h" #include "php_v8_return_value.h" diff --git a/src/php_v8_function_callback_info.cc b/src/php_v8_function_callback_info.cc index d097e7f..b660f6b 100644 --- a/src/php_v8_function_callback_info.cc +++ b/src/php_v8_function_callback_info.cc @@ -16,7 +16,6 @@ #include "php_v8_function_callback_info.h" #include "php_v8_exceptions.h" -#include "php_v8_callback_info.h" #include "php_v8_return_value.h" #include "php_v8_value.h" #include "php_v8.h" @@ -46,21 +45,21 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value // common to both callback structures: // isolate ZVAL_OBJ(&tmp, &php_v8_isolate->std); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("isolate"), &tmp); + zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("isolate"), &tmp); // context ZVAL_OBJ(&tmp, &php_v8_context->std); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("context"), &tmp); + zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("context"), &tmp); // this php_v8_get_or_create_value(&tmp, args.This(), php_v8_isolate); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("this"), &tmp); + zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("this"), &tmp); Z_DELREF(tmp); // holder php_v8_get_or_create_value(&tmp, args.Holder(), php_v8_isolate); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("holder"), &tmp); + zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("holder"), &tmp); Z_DELREF(tmp); // return value php_v8_return_value = php_v8_return_value_create_from_return_value(&tmp, php_v8_context, PHP_V8_RETVAL_ACCEPTS_ANY); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("return_value"), &tmp); + zend_update_property(php_v8_function_callback_info_class_entry, return_value, ZEND_STRL("return_value"), &tmp); Z_DELREF(tmp); // specific to function callback structure: @@ -86,6 +85,66 @@ php_v8_return_value_t * php_v8_callback_info_create_from_info(zval *return_value return php_v8_return_value; } +static PHP_METHOD(CallbackInfo, getIsolate) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("isolate"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(CallbackInfo, getContext) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("context"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(CallbackInfo, this) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("this"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(CallbackInfo, holder) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("holder"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(CallbackInfo, getReturnValue) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("return_value"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + static PHP_METHOD(FunctionCallbackInfo, length) { zval rv; zval *tmp; @@ -136,6 +195,21 @@ static PHP_METHOD(FunctionCallbackInfo, isConstructCall) { } +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIsolate, ZEND_RETURN_VALUE, 0, V8\\Isolate, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_this, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_holder, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getReturnValue, ZEND_RETURN_VALUE, 0, V8\\ReturnValue, 0) +ZEND_END_ARG_INFO() + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_length, ZEND_RETURN_VALUE, 0, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -150,6 +224,11 @@ ZEND_END_ARG_INFO() static const zend_function_entry php_v8_function_callback_info_methods[] = { + PHP_V8_ME(CallbackInfo, this, ZEND_ACC_PUBLIC) + PHP_V8_ME(CallbackInfo, holder, ZEND_ACC_PUBLIC) + PHP_V8_ME(CallbackInfo, getIsolate, ZEND_ACC_PUBLIC) + PHP_V8_ME(CallbackInfo, getContext, ZEND_ACC_PUBLIC) + PHP_V8_ME(CallbackInfo, getReturnValue, ZEND_ACC_PUBLIC) PHP_V8_ME(FunctionCallbackInfo, length, ZEND_ACC_PUBLIC) PHP_V8_ME(FunctionCallbackInfo, arguments, ZEND_ACC_PUBLIC) PHP_V8_ME(FunctionCallbackInfo, newTarget, ZEND_ACC_PUBLIC) @@ -161,8 +240,13 @@ PHP_MINIT_FUNCTION(php_v8_function_callback_info) { zend_class_entry ce; INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "FunctionCallbackInfo", php_v8_function_callback_info_methods); - this_ce = zend_register_internal_class_ex(&ce, php_v8_callback_info_class_entry); + this_ce = zend_register_internal_class(&ce); + zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("context"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("this"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("holder"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("return_value"), ZEND_ACC_PRIVATE); zend_declare_property_null(this_ce, ZEND_STRL("arguments"), ZEND_ACC_PRIVATE); zend_declare_property_null(this_ce, ZEND_STRL("new_target"), ZEND_ACC_PRIVATE); zend_declare_property_null(this_ce, ZEND_STRL("is_constructor_call"), ZEND_ACC_PRIVATE); diff --git a/src/php_v8_function_callback_info.h b/src/php_v8_function_callback_info.h index 308506b..e496440 100644 --- a/src/php_v8_function_callback_info.h +++ b/src/php_v8_function_callback_info.h @@ -14,7 +14,6 @@ #define PHP_V8_FUNCTION_CALLBACK_INFO_H #include "php_v8_return_value.h" -#include "php_v8_callback_info.h" #include extern "C" { diff --git a/src/php_v8_property_callback_info.cc b/src/php_v8_property_callback_info.cc index cffd664..8989a09 100644 --- a/src/php_v8_property_callback_info.cc +++ b/src/php_v8_property_callback_info.cc @@ -15,7 +15,6 @@ #endif #include "php_v8_property_callback_info.h" -#include "php_v8_callback_info.h" #include "php_v8_return_value.h" #include "php_v8_value.h" #include "php_v8.h" @@ -69,21 +68,21 @@ php_v8_return_value_t *php_v8_callback_info_create_from_info_meta(zval *return_v // common to both callback structures: // isolate ZVAL_OBJ(&tmp, &php_v8_isolate->std); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("isolate"), &tmp); + zend_update_property(php_v8_property_callback_info_class_entry, return_value, ZEND_STRL("isolate"), &tmp); // context ZVAL_OBJ(&tmp, &php_v8_context->std); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("context"), &tmp); + zend_update_property(php_v8_property_callback_info_class_entry, return_value, ZEND_STRL("context"), &tmp); // this php_v8_get_or_create_value(&tmp, args.This(), php_v8_isolate); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("this"), &tmp); + zend_update_property(php_v8_property_callback_info_class_entry, return_value, ZEND_STRL("this"), &tmp); Z_DELREF(tmp); // holder php_v8_get_or_create_value(&tmp, args.Holder(), php_v8_isolate); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("holder"), &tmp); + zend_update_property(php_v8_property_callback_info_class_entry, return_value, ZEND_STRL("holder"), &tmp); Z_DELREF(tmp); // return value php_v8_return_value = php_v8_return_value_create_from_return_value(&tmp, php_v8_context, PHP_V8_RETVAL_ACCEPTS_ANY); - zend_update_property(php_v8_callback_info_class_entry, return_value, ZEND_STRL("return_value"), &tmp); + zend_update_property(php_v8_property_callback_info_class_entry, return_value, ZEND_STRL("return_value"), &tmp); Z_DELREF(tmp); // specific to property callback structure: @@ -93,6 +92,67 @@ php_v8_return_value_t *php_v8_callback_info_create_from_info_meta(zval *return_v return php_v8_return_value; } + +static PHP_METHOD(PropertyCallbackInfo, getIsolate) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("isolate"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(PropertyCallbackInfo, getContext) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("context"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(PropertyCallbackInfo, this) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("this"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(PropertyCallbackInfo, holder) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("holder"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + +static PHP_METHOD(PropertyCallbackInfo, getReturnValue) { + zval rv; + zval *tmp; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + tmp = zend_read_property(this_ce, getThis(), ZEND_STRL("return_value"), 0, &rv); + ZVAL_COPY(return_value, tmp); +} + static PHP_METHOD(PropertyCallbackInfo, shouldThrowOnError) { zval rv; zval *tmp; @@ -105,10 +165,32 @@ static PHP_METHOD(PropertyCallbackInfo, shouldThrowOnError) { ZVAL_COPY(return_value, tmp); } + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getIsolate, ZEND_RETURN_VALUE, 0, V8\\Isolate, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_this, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_holder, ZEND_RETURN_VALUE, 0, V8\\ObjectValue, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getReturnValue, ZEND_RETURN_VALUE, 0, V8\\ReturnValue, 0) +ZEND_END_ARG_INFO() + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_shouldThrowOnError, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() + static const zend_function_entry php_v8_property_callback_info_methods[] = { + PHP_V8_ME(PropertyCallbackInfo, this, ZEND_ACC_PUBLIC) + PHP_V8_ME(PropertyCallbackInfo, holder, ZEND_ACC_PUBLIC) + PHP_V8_ME(PropertyCallbackInfo, getIsolate, ZEND_ACC_PUBLIC) + PHP_V8_ME(PropertyCallbackInfo, getContext, ZEND_ACC_PUBLIC) + PHP_V8_ME(PropertyCallbackInfo, getReturnValue, ZEND_ACC_PUBLIC) PHP_V8_ME(PropertyCallbackInfo, shouldThrowOnError, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -116,8 +198,13 @@ static const zend_function_entry php_v8_property_callback_info_methods[] = { PHP_MINIT_FUNCTION (php_v8_property_callback_info) { zend_class_entry ce; INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "PropertyCallbackInfo", php_v8_property_callback_info_methods); - this_ce = zend_register_internal_class_ex(&ce, php_v8_callback_info_class_entry); + this_ce = zend_register_internal_class(&ce); + zend_declare_property_null(this_ce, ZEND_STRL("isolate"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("context"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("this"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("holder"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("return_value"), ZEND_ACC_PRIVATE); zend_declare_property_null(this_ce, ZEND_STRL("should_throw_on_error"), ZEND_ACC_PRIVATE); return SUCCESS; diff --git a/src/php_v8_property_callback_info.h b/src/php_v8_property_callback_info.h index 2479135..d162891 100644 --- a/src/php_v8_property_callback_info.h +++ b/src/php_v8_property_callback_info.h @@ -14,7 +14,6 @@ #define PHP_V8_PROPERTY_CALLBACK_INFO_H #include "php_v8_return_value.h" -#include "php_v8_callback_info.h" #include extern "C" { diff --git a/stubs/src/CallbackInfo.php b/stubs/src/CallbackInfo.php deleted file mode 100644 index 4e81000..0000000 --- a/stubs/src/CallbackInfo.php +++ /dev/null @@ -1,67 +0,0 @@ - - * - * Licensed under the MIT license: http://opensource.org/licenses/MIT - * - * For the full copyright and license information, please view the - * LICENSE file that was distributed with this source or visit - * http://opensource.org/licenses/MIT - */ - - -namespace V8; - -class CallbackInfo -{ - /** - * @return Isolate - */ - public function getIsolate(): Isolate - { - } - - /** - * @return Context - */ - public function getContext(): Context - { - } - - /** - * Returns the receiver. This corresponds to the "this" value. - * - * @return ObjectValue - */ - public function this(): ObjectValue - { - } - - /** - * If the callback was created without a Signature, this is the same - * value as This(). If there is a signature, and the signature didn't match - * This() but one of its hidden prototypes, this will be the respective - * hidden prototype. - * - * Note that this is not the prototype of This() on which the accessor - * referencing this callback was found (which in V8 internally is often - * referred to as holder [sic]). - * - * @return ObjectValue - */ - public function holder(): ObjectValue - { - } - - /** - * The ReturnValue for the call - * - * @return ReturnValue - */ - public function getReturnValue(): ReturnValue - { - } -} diff --git a/stubs/src/FunctionCallbackInfo.php b/stubs/src/FunctionCallbackInfo.php index 90a1430..d080c91 100644 --- a/stubs/src/FunctionCallbackInfo.php +++ b/stubs/src/FunctionCallbackInfo.php @@ -22,8 +22,56 @@ * including the receiver, the number and values of arguments, and * the holder of the function. */ -class FunctionCallbackInfo extends CallbackInfo +class FunctionCallbackInfo { + /** + * @return Isolate + */ + public function getIsolate(): Isolate + { + } + + /** + * @return Context + */ + public function getContext(): Context + { + } + + /** + * Returns the receiver. This corresponds to the "this" value. + * + * @return ObjectValue + */ + public function this(): ObjectValue + { + } + + /** + * If the callback was created without a Signature, this is the same + * value as This(). If there is a signature, and the signature didn't match + * This() but one of its hidden prototypes, this will be the respective + * hidden prototype. + * + * Note that this is not the prototype of This() on which the accessor + * referencing this callback was found (which in V8 internally is often + * referred to as holder [sic]). + * + * @return ObjectValue + */ + public function holder(): ObjectValue + { + } + + /** + * The ReturnValue for the call + * + * @return ReturnValue + */ + public function getReturnValue(): ReturnValue + { + } + /** * @return int */ diff --git a/stubs/src/PropertyCallbackInfo.php b/stubs/src/PropertyCallbackInfo.php index edecab8..53c9457 100644 --- a/stubs/src/PropertyCallbackInfo.php +++ b/stubs/src/PropertyCallbackInfo.php @@ -19,8 +19,56 @@ * The information passed to a property callback about the context * of the property access. */ -class PropertyCallbackInfo extends CallbackInfo +class PropertyCallbackInfo { + /** + * @return Isolate + */ + public function getIsolate(): Isolate + { + } + + /** + * @return Context + */ + public function getContext(): Context + { + } + + /** + * Returns the receiver. This corresponds to the "this" value. + * + * @return ObjectValue + */ + public function this(): ObjectValue + { + } + + /** + * If the callback was created without a Signature, this is the same + * value as This(). If there is a signature, and the signature didn't match + * This() but one of its hidden prototypes, this will be the respective + * hidden prototype. + * + * Note that this is not the prototype of This() on which the accessor + * referencing this callback was found (which in V8 internally is often + * referred to as holder [sic]). + * + * @return ObjectValue + */ + public function holder(): ObjectValue + { + } + + /** + * The ReturnValue for the call + * + * @return ReturnValue + */ + public function getReturnValue(): ReturnValue + { + } + /** * Returns true if the intercepted function should throw if an error occurs. * Usually, true corresponds to 'use strict'. diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index c601865..016f491 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -884,28 +884,34 @@ class V8\ReturnValue public function getContext(): V8\Context public function inContext(): bool -class V8\CallbackInfo +class V8\PropertyCallbackInfo private $isolate private $context private $this private $holder private $return_value + private $should_throw_on_error public function this(): V8\ObjectValue public function holder(): V8\ObjectValue public function getIsolate(): V8\Isolate public function getContext(): V8\Context public function getReturnValue(): V8\ReturnValue - -class V8\PropertyCallbackInfo - extends V8\CallbackInfo - private $should_throw_on_error public function shouldThrowOnError(): bool class V8\FunctionCallbackInfo - extends V8\CallbackInfo + private $isolate + private $context + private $this + private $holder + private $return_value private $arguments private $new_target private $is_constructor_call + public function this(): V8\ObjectValue + public function holder(): V8\ObjectValue + public function getIsolate(): V8\Isolate + public function getContext(): V8\Context + public function getReturnValue(): V8\ReturnValue public function length(): int public function arguments(): array public function newTarget(): V8\Value diff --git a/tests/FunctionCallbackInfo.phpt b/tests/FunctionCallbackInfo.phpt index fb79bc5..2a26de6 100644 --- a/tests/FunctionCallbackInfo.phpt +++ b/tests/FunctionCallbackInfo.phpt @@ -77,16 +77,16 @@ Function called Object representation: ---------------------- object(V8\FunctionCallbackInfo)#10 (8) { - ["isolate":"V8\CallbackInfo":private]=> + ["isolate":"V8\FunctionCallbackInfo":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { } - ["context":"V8\CallbackInfo":private]=> + ["context":"V8\FunctionCallbackInfo":private]=> object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { } } - ["this":"V8\CallbackInfo":private]=> + ["this":"V8\FunctionCallbackInfo":private]=> object(V8\ObjectValue)#11 (2) { ["isolate":"V8\Value":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { @@ -98,7 +98,7 @@ object(V8\FunctionCallbackInfo)#10 (8) { } } } - ["holder":"V8\CallbackInfo":private]=> + ["holder":"V8\FunctionCallbackInfo":private]=> object(V8\ObjectValue)#11 (2) { ["isolate":"V8\Value":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { @@ -110,7 +110,7 @@ object(V8\FunctionCallbackInfo)#10 (8) { } } } - ["return_value":"V8\CallbackInfo":private]=> + ["return_value":"V8\FunctionCallbackInfo":private]=> object(V8\ReturnValue)#12 (2) { ["isolate":"V8\ReturnValue":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { @@ -178,16 +178,16 @@ object(V8\ReturnValue)#12 (2) { Object representation (outside of context): ------------------------------------------- object(V8\FunctionCallbackInfo)#10 (8) { - ["isolate":"V8\CallbackInfo":private]=> + ["isolate":"V8\FunctionCallbackInfo":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { } - ["context":"V8\CallbackInfo":private]=> + ["context":"V8\FunctionCallbackInfo":private]=> object(V8\Context)#4 (1) { ["isolate":"V8\Context":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { } } - ["this":"V8\CallbackInfo":private]=> + ["this":"V8\FunctionCallbackInfo":private]=> object(V8\ObjectValue)#11 (2) { ["isolate":"V8\Value":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { @@ -199,7 +199,7 @@ object(V8\FunctionCallbackInfo)#10 (8) { } } } - ["holder":"V8\CallbackInfo":private]=> + ["holder":"V8\FunctionCallbackInfo":private]=> object(V8\ObjectValue)#11 (2) { ["isolate":"V8\Value":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { @@ -211,7 +211,7 @@ object(V8\FunctionCallbackInfo)#10 (8) { } } } - ["return_value":"V8\CallbackInfo":private]=> + ["return_value":"V8\FunctionCallbackInfo":private]=> object(V8\ReturnValue)#12 (2) { ["isolate":"V8\ReturnValue":private]=> object(v8Tests\TrackingDtors\Isolate)#2 (0) { diff --git a/tests/Isolate_isInUse.phpt b/tests/Isolate_isInUse.phpt index c12c30c..8a62322 100644 --- a/tests/Isolate_isInUse.phpt +++ b/tests/Isolate_isInUse.phpt @@ -19,7 +19,7 @@ $isolate = new V8\Isolate(); $helper->inline_dump('Isolate in use', $isolate->isInUse()); $context = new V8\Context($isolate); -$fnc = new \V8\FunctionObject($context, function (\V8\CallbackInfo $info) use ($helper) { +$fnc = new \V8\FunctionObject($context, function (\V8\FunctionCallbackInfo $info) use ($helper) { $helper->inline_dump('Isolate in use', $info->getIsolate()->isInUse()); }); diff --git a/tests/PropertyCallbackInfo.phpt b/tests/PropertyCallbackInfo.phpt index 66327eb..77967b0 100644 --- a/tests/PropertyCallbackInfo.phpt +++ b/tests/PropertyCallbackInfo.phpt @@ -60,16 +60,16 @@ Property callback called Object representation: ---------------------- object(V8\PropertyCallbackInfo)#8 (6) { - ["isolate":"V8\CallbackInfo":private]=> + ["isolate":"V8\PropertyCallbackInfo":private]=> object(V8\Isolate)#2 (0) { } - ["context":"V8\CallbackInfo":private]=> + ["context":"V8\PropertyCallbackInfo":private]=> object(V8\Context)#3 (1) { ["isolate":"V8\Context":private]=> object(V8\Isolate)#2 (0) { } } - ["this":"V8\CallbackInfo":private]=> + ["this":"V8\PropertyCallbackInfo":private]=> object(V8\ObjectValue)#5 (2) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#2 (0) { @@ -81,7 +81,7 @@ object(V8\PropertyCallbackInfo)#8 (6) { } } } - ["holder":"V8\CallbackInfo":private]=> + ["holder":"V8\PropertyCallbackInfo":private]=> object(V8\ObjectValue)#5 (2) { ["isolate":"V8\Value":private]=> object(V8\Isolate)#2 (0) { @@ -93,7 +93,7 @@ object(V8\PropertyCallbackInfo)#8 (6) { } } } - ["return_value":"V8\CallbackInfo":private]=> + ["return_value":"V8\PropertyCallbackInfo":private]=> object(V8\ReturnValue)#9 (2) { ["isolate":"V8\ReturnValue":private]=> object(V8\Isolate)#2 (0) { diff --git a/v8.cc b/v8.cc index 736a5e8..a66e71e 100644 --- a/v8.cc +++ b/v8.cc @@ -62,7 +62,6 @@ #include "php_v8_object.h" #include "php_v8_template.h" #include "php_v8_return_value.h" -#include "php_v8_callback_info.h" #include "php_v8_property_callback_info.h" #include "php_v8_function_callback_info.h" #include "php_v8_named_property_handler_configuration.h" @@ -162,7 +161,6 @@ PHP_MINIT_FUNCTION(v8) PHP_MINIT(php_v8_return_value)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(php_v8_callback_info)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_property_callback_info)(INIT_FUNC_ARGS_PASSTHRU); /* PropertyCallbackInfo inherits CallbackInfo */ PHP_MINIT(php_v8_function_callback_info)(INIT_FUNC_ARGS_PASSTHRU); /* FunctionCallbackInfo inherits CallbackInfo */ From 9303a479ff7fc70d879813ec78ee24ed52c0fa0d Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 14:38:41 +0300 Subject: [PATCH 09/17] Add immutable prototype chains to ObjectTemplate, closes #58 --- src/php_v8_object_template.cc | 59 +++++++++++++++++++----- stubs/src/ObjectTemplate.php | 20 ++++++++ tests/001-verify_extension_entities.phpt | 2 + tests/ObjectTemplate.phpt | 7 +++ 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/src/php_v8_object_template.cc b/src/php_v8_object_template.cc index 5cc44c9..0d2777e 100644 --- a/src/php_v8_object_template.cc +++ b/src/php_v8_object_template.cc @@ -372,6 +372,33 @@ static PHP_METHOD(ObjectTemplate, setCallAsFunctionHandler) { local_template->SetCallAsFunctionHandler(callback, data); } +static PHP_METHOD(ObjectTemplate, isImmutableProto) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + PHP_V8_FETCH_OBJECT_TEMPLATE_WITH_CHECK(getThis(), php_v8_object_template); + PHP_V8_ENTER_STORED_ISOLATE(php_v8_object_template); + + v8::Local local_obj_tpl = php_v8_object_template_get_local(php_v8_object_template); + + RETURN_BOOL(static_cast(local_obj_tpl->IsImmutableProto())); +} + +static PHP_METHOD(ObjectTemplate, setImmutableProto) { + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + PHP_V8_FETCH_OBJECT_TEMPLATE_WITH_CHECK(getThis(), php_v8_object_template); + PHP_V8_ENTER_STORED_ISOLATE(php_v8_object_template); + + v8::Local local_obj_tpl = php_v8_object_template_get_local(php_v8_object_template); + + local_obj_tpl->SetImmutableProto(); +} + + /* Non-standard, implementations of AdjustableExternalMemoryInterface::AdjustExternalAllocatedMemory */ static PHP_METHOD(ObjectTemplate, adjustExternalAllocatedMemory) { php_v8_ext_mem_interface_object_template_AdjustExternalAllocatedMemory(INTERNAL_FUNCTION_PARAM_PASSTHRU); @@ -443,6 +470,12 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_setCallAsFunctionHandler, ZEND_ARG_INFO(0, callback) ZEND_END_ARG_INFO() +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_isImmutableProto, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_setImmutableProto, 0) +ZEND_END_ARG_INFO() + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_adjustExternalAllocatedMemory, ZEND_RETURN_VALUE, 1, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, change_in_bytes, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -453,18 +486,20 @@ ZEND_END_ARG_INFO() static const zend_function_entry php_v8_object_template_methods[] = { - PHP_V8_ME(ObjectTemplate, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_V8_ME(ObjectTemplate, getIsolate, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, set, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, setAccessorProperty, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, setNativeDataProperty, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, newInstance, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, setAccessor, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, setHandlerForNamedProperty, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, setHandlerForIndexedProperty, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, setCallAsFunctionHandler, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, adjustExternalAllocatedMemory, ZEND_ACC_PUBLIC) - PHP_V8_ME(ObjectTemplate, getExternalAllocatedMemory, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_V8_ME(ObjectTemplate, getIsolate, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, set, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setAccessorProperty, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setNativeDataProperty, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, newInstance, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setAccessor, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setHandlerForNamedProperty, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setHandlerForIndexedProperty, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setCallAsFunctionHandler, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, isImmutableProto, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, setImmutableProto, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, adjustExternalAllocatedMemory, ZEND_ACC_PUBLIC) + PHP_V8_ME(ObjectTemplate, getExternalAllocatedMemory, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/stubs/src/ObjectTemplate.php b/stubs/src/ObjectTemplate.php index ce1b70d..684807e 100644 --- a/stubs/src/ObjectTemplate.php +++ b/stubs/src/ObjectTemplate.php @@ -120,6 +120,26 @@ public function setCallAsFunctionHandler(callable $callback) { } + + /** + * Returns true if the object will be an immutable prototype exotic object. + * + * @return bool + */ + public function isImmutableProto(): bool + { + } + + /** + * Makes the ObjectTempate for an immutable prototype exotic object, with an + * immutable __proto__. + * + * @return bool + */ + public function setImmutableProto(): bool + { + } + /** * {@inheritdoc} */ diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index 016f491..f6628be 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -843,6 +843,8 @@ class V8\ObjectTemplate public function setHandlerForNamedProperty(V8\NamedPropertyHandlerConfiguration $configuration) public function setHandlerForIndexedProperty(V8\IndexedPropertyHandlerConfiguration $configuration) public function setCallAsFunctionHandler($callback) + public function isImmutableProto(): bool + public function setImmutableProto() public function adjustExternalAllocatedMemory(int $change_in_bytes): int public function getExternalAllocatedMemory(): int diff --git a/tests/ObjectTemplate.phpt b/tests/ObjectTemplate.phpt index 803ba66..474ff88 100644 --- a/tests/ObjectTemplate.phpt +++ b/tests/ObjectTemplate.phpt @@ -44,6 +44,10 @@ $instance = $value->newInstance($context); $helper->assert('ObjectTemplate instance has name from constructor', $instance->getConstructorName()->value() == 'TestConstructor'); +$helper->line(); +$helper->assert('Object template is not immutable prototype by default', $value->isImmutableProto(), false); +$value->setImmutableProto(); +$helper->assert('Object template is now set to be immutable prototype', $value->isImmutableProto(), true); ?> --EXPECT-- @@ -64,3 +68,6 @@ Accessors: V8\ObjectTemplate::getIsolate() matches expected value ObjectTemplate instance has name from constructor: ok + +Object template is not immutable prototype by default: ok +Object template is now set to be immutable prototype: ok From 5341a5df6aa344009326e8175730745771ab762a Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 14:56:04 +0300 Subject: [PATCH 10/17] Add StartupData::warmUpSnapshotDataBlob(), closes #59 --- src/php_v8_startup_data.cc | 41 ++++++++++++++++-- stubs/src/StartupData.php | 16 +++++++ tests/001-verify_extension_entities.phpt | 1 + tests/StartupData_warmUpSnapshotDataBlob.phpt | 42 +++++++++++++++++++ 4 files changed, 96 insertions(+), 4 deletions(-) create mode 100644 tests/StartupData_warmUpSnapshotDataBlob.phpt diff --git a/src/php_v8_startup_data.cc b/src/php_v8_startup_data.cc index ca08707..20d39fa 100644 --- a/src/php_v8_startup_data.cc +++ b/src/php_v8_startup_data.cc @@ -140,6 +140,33 @@ static PHP_METHOD(StartupData, createFromSource) { php_v8_startup_data_create(return_value, startup_blob); } +static PHP_METHOD(StartupData, warmUpSnapshotDataBlob) { + zval *php_cold_data_zv; + zend_string *source = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "oS", &php_cold_data_zv, &source) == FAILURE) { + return; + } + + PHP_V8_STARTUP_DATA_FETCH_INTO(php_cold_data_zv, php_v8_cold_data); + + /* we can't try-catch here while we have no isolate yet */ + + const char *warmup_source = ZSTR_VAL(source); + php_v8_init(); + + v8::StartupData *warm_data = new v8::StartupData(); + + *warm_data = v8::V8::WarmUpSnapshotDataBlob(*php_v8_cold_data->blob->data(), warmup_source); + + if (warm_data->data == NULL) { + PHP_V8_THROW_EXCEPTION("Failed to warm up snapshot"); + return; + } + + php_v8_startup_data_create(return_value, warm_data); +} + PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 1) ZEND_ARG_TYPE_INFO(0, blob, IS_STRING, 0) @@ -155,12 +182,18 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_createFromSource, ZEND_RET ZEND_ARG_TYPE_INFO(0, source, IS_STRING, 0) ZEND_END_ARG_INFO() +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_warmUpSnapshotDataBlob, ZEND_RETURN_VALUE, 2, V8\\StartupData, 0) + ZEND_ARG_OBJ_INFO(0, cold_startup_data, V8\\StartupData, 0) + ZEND_ARG_TYPE_INFO(0, warmup_source, IS_STRING, 0) +ZEND_END_ARG_INFO() + static const zend_function_entry php_v8_startup_data_methods[] = { - PHP_V8_ME(StartupData, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) - PHP_V8_ME(StartupData, getData, ZEND_ACC_PUBLIC) - PHP_V8_ME(StartupData, getRawSize, ZEND_ACC_PUBLIC) - PHP_V8_ME(StartupData, createFromSource, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(StartupData, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) + PHP_V8_ME(StartupData, getData, ZEND_ACC_PUBLIC) + PHP_V8_ME(StartupData, getRawSize, ZEND_ACC_PUBLIC) + PHP_V8_ME(StartupData, createFromSource, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(StartupData, warmUpSnapshotDataBlob, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END }; diff --git a/stubs/src/StartupData.php b/stubs/src/StartupData.php index e0d4d55..6221a78 100644 --- a/stubs/src/StartupData.php +++ b/stubs/src/StartupData.php @@ -46,4 +46,20 @@ public static function createFromSource(string $source): StartupData return new self($blob); } + + /** + * Bootstrap an isolate and a context from the cold startup blob, run the + * warm-up script to trigger code compilation. The side effects are then + * discarded. The resulting startup snapshot will include compiled code. + * + * The argument startup blob is untouched. + * + * @param StartupData $cold_startup_data + * @param string $warmup_source + * + * @return StartupData + */ + public static function warmUpSnapshotDataBlob(StartupData $cold_startup_data, string $warmup_source): StartupData + { + } } diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index f6628be..a1950fd 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -325,6 +325,7 @@ class V8\StartupData public function getData(): string public function getRawSize(): int public static function createFromSource(string $source): V8\StartupData + public static function warmUpSnapshotDataBlob(V8\StartupData $cold_startup_data, string $warmup_source): V8\StartupData class V8\Isolate const MEMORY_PRESSURE_LEVEL_NONE = 0 diff --git a/tests/StartupData_warmUpSnapshotDataBlob.phpt b/tests/StartupData_warmUpSnapshotDataBlob.phpt new file mode 100644 index 0000000..bb59a86 --- /dev/null +++ b/tests/StartupData_warmUpSnapshotDataBlob.phpt @@ -0,0 +1,42 @@ +--TEST-- +V8\StartupData::warmUpSnapshotDataBlob +--SKIPIF-- + +--ENV-- +HOME=/tmp/we-need-home-env-var-set-to-load-valgrindrc +--FILE-- +assert('Context should have test function', $v8_helper->CompileTryRun($context, 'test_snapshot()')->value(), 'hello, world'); + +$wam_source = 'test_snapshot = function () { return "hello, warm world";}'; + +$warm_data = V8\StartupData::warmUpSnapshotDataBlob($data, $wam_source); + + +$isolate = new V8\Isolate($warm_data); +$context = new \V8\Context($isolate); + + +$helper->assert('Warm data has no side effects', $res = $v8_helper->CompileTryRun($context, 'test_snapshot()')->value(), 'hello, world'); + + +?> +--EXPECT-- +Context should have test function: ok +Warm data has no side effects: ok From a8404d6175104835ce132a6bfb45c1f5e14e5e99 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 15:52:13 +0300 Subject: [PATCH 11/17] Add missed JSON class support, closes #56 --- config.m4 | 1 + src/php_v8_json.cc | 124 +++++++++++++++++++++++ src/php_v8_json.h | 29 ++++++ stubs/src/JSON.php | 49 +++++++++ tests/001-verify_extension_entities.phpt | 4 + tests/JSON.phpt | 110 ++++++++++++++++++++ v8.cc | 3 + 7 files changed, 320 insertions(+) create mode 100644 src/php_v8_json.cc create mode 100644 src/php_v8_json.h create mode 100644 stubs/src/JSON.php create mode 100644 tests/JSON.phpt diff --git a/config.m4 b/config.m4 index 04240ba..433ed0e 100644 --- a/config.m4 +++ b/config.m4 @@ -215,6 +215,7 @@ if test "$PHP_V8" != "no"; then src/php_v8_property_callback_info.cc \ src/php_v8_named_property_handler_configuration.cc \ src/php_v8_indexed_property_handler_configuration.cc \ + src/php_v8_json.cc \ ], $ext_shared, , -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_ADD_BUILD_DIR($ext_builddir/src) diff --git a/src/php_v8_json.cc b/src/php_v8_json.cc new file mode 100644 index 0000000..2a21f2d --- /dev/null +++ b/src/php_v8_json.cc @@ -0,0 +1,124 @@ +/* + * This file is part of the pinepain/php-v8 PHP extension. + * + * Copyright (c) 2015-2017 Bogdan Padalko + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php_v8_json.h" +#include "php_v8_value.h" +#include "php_v8_context.h" +#include "php_v8.h" + +zend_class_entry *php_v8_json_class_entry; +#define this_ce php_v8_json_class_entry + + +static PHP_METHOD(JSON, parse) { + zval *php_v8_context_zv; + zval *php_v8_string_zv; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "oo", &php_v8_context_zv, &php_v8_string_zv) == FAILURE) { + return; + } + + PHP_V8_VALUE_FETCH_WITH_CHECK(php_v8_string_zv, php_v8_string); + PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context); + + PHP_V8_DATA_ISOLATES_CHECK(php_v8_context, php_v8_string); + + PHP_V8_ENTER_STORED_ISOLATE(php_v8_context); + PHP_V8_ENTER_CONTEXT(php_v8_context); + + v8::Local local_string = php_v8_value_get_local_as(php_v8_string); + + PHP_V8_TRY_CATCH(isolate); + PHP_V8_INIT_ISOLATE_LIMITS_ON_CONTEXT(php_v8_context); + + v8::MaybeLocal maybe_local_value = v8::JSON::Parse(context, local_string); + + PHP_V8_MAYBE_CATCH(php_v8_context, try_catch); + PHP_V8_THROW_EXCEPTION_WHEN_EMPTY(maybe_local_value, "Failed to parse"); + + php_v8_get_or_create_value(return_value, maybe_local_value.ToLocalChecked(), php_v8_context->php_v8_isolate); +} + +static PHP_METHOD(JSON, stringify) { + zval *php_v8_context_zv; + zval *php_v8_value_zv = NULL; + zval *php_v8_gap_zv = NULL; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "oo|o", &php_v8_context_zv, &php_v8_value_zv, &php_v8_gap_zv) == FAILURE) { + return; + } + + PHP_V8_CONTEXT_FETCH_WITH_CHECK(php_v8_context_zv, php_v8_context); + PHP_V8_VALUE_FETCH_WITH_CHECK(php_v8_value_zv, php_v8_value); + + PHP_V8_DATA_ISOLATES_CHECK(php_v8_context, php_v8_value); + + PHP_V8_ENTER_STORED_ISOLATE(php_v8_context); + PHP_V8_ENTER_CONTEXT(php_v8_context); + + v8::Local local_gap; + + if (NULL != php_v8_gap_zv) { + PHP_V8_VALUE_FETCH_WITH_CHECK(php_v8_gap_zv, php_v8_gap); + PHP_V8_DATA_ISOLATES_CHECK(php_v8_context, php_v8_gap); + local_gap = php_v8_value_get_local_as(php_v8_gap); + } + + v8::Local local_value = php_v8_value_get_local_as(php_v8_value); + + PHP_V8_TRY_CATCH(isolate); + PHP_V8_INIT_ISOLATE_LIMITS_ON_CONTEXT(php_v8_context); + + v8::MaybeLocal maybe_local_string = v8::JSON::Stringify(context, local_value, local_gap); + + PHP_V8_MAYBE_CATCH(php_v8_context, try_catch); + PHP_V8_THROW_EXCEPTION_WHEN_EMPTY(maybe_local_string, "Failed to stringify"); + + v8::String::Utf8Value str(isolate, maybe_local_string.ToLocalChecked()); + + PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(str, cstr); + + RETVAL_STRINGL(cstr, str.length()); +} + + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_parse, ZEND_RETURN_VALUE, 2, V8\\Value, 0) + ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) + ZEND_ARG_OBJ_INFO(0, json_string, V8\\StringValue, 0) +ZEND_END_ARG_INFO() + +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_stringify, ZEND_RETURN_VALUE, 2, IS_STRING, 0) + ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) + ZEND_ARG_OBJ_INFO(0, json_value, V8\\Value, 0) + ZEND_ARG_OBJ_INFO(0, gap, V8\\StringValue, 1) +ZEND_END_ARG_INFO() + + +static const zend_function_entry php_v8_json_methods[] = { + PHP_V8_ME(JSON, parse, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(JSON, stringify, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + + PHP_FE_END +}; + + +PHP_MINIT_FUNCTION(php_v8_json) { + zend_class_entry ce; + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "JSON", php_v8_json_methods); + this_ce = zend_register_internal_class(&ce); + + return SUCCESS; +} diff --git a/src/php_v8_json.h b/src/php_v8_json.h new file mode 100644 index 0000000..4d61c77 --- /dev/null +++ b/src/php_v8_json.h @@ -0,0 +1,29 @@ +/* + * This file is part of the pinepain/php-v8 PHP extension. + * + * Copyright (c) 2015-2017 Bogdan Padalko + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + +#ifndef PHP_V8_JSON_H +#define PHP_V8_JSON_H + +extern "C" { +#include "php.h" + +#ifdef ZTS +#include "TSRM.h" +#endif +} + +extern zend_class_entry* php_v8_json_class_entry; + + +PHP_MINIT_FUNCTION(php_v8_json); + +#endif //PHP_V8_JSON_H diff --git a/stubs/src/JSON.php b/stubs/src/JSON.php new file mode 100644 index 0000000..1fc0bdb --- /dev/null +++ b/stubs/src/JSON.php @@ -0,0 +1,49 @@ + + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + +namespace V8; + +/** + * A JSON Parser and Stringifier. + */ +class JSON extends IntegerValue +{ + /** + * Tries to parse the string |json_string| and returns it as value if + * successful. + * + * @param Context $context + * @param String $json_string The string to parse. + * + * @return Value|PrimitiveValue|ObjectValue + */ + public static function parse(Context $context, String $json_string): Value + { + } + + /** + * Tries to stringify the JSON-serializable object |json_object| and returns + * it as string if successful. + * + * @param Context $context + * @param Value $json_value The JSON-serializable value to stringify. + * @param String|null $gap + * + * @return string + */ + public static function stringify(Context $context, Value $json_value, String $gap = null): string + { + } +} diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index a1950fd..8f77e81 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -925,3 +925,7 @@ class V8\NamedPropertyHandlerConfiguration class V8\IndexedPropertyHandlerConfiguration public function __construct(callable $getter, ?callable $setter, ?callable $query, ?callable $deleter, ?callable $enumerator, int $flags) + +class V8\JSON + public static function parse(V8\Context $context, V8\StringValue $json_string): V8\Value + public static function stringify(V8\Context $context, V8\Value $json_value, ?V8\StringValue $gap): string diff --git a/tests/JSON.phpt b/tests/JSON.phpt new file mode 100644 index 0000000..d093775 --- /dev/null +++ b/tests/JSON.phpt @@ -0,0 +1,110 @@ +--TEST-- +JSON +--SKIPIF-- + +--ENV-- +HOME=/tmp/we-need-home-env-var-set-to-load-valgrindrc +--FILE-- +header('Parse'); + +$res = V8\JSON::parse($context, new V8\StringValue($isolate, '"test"')); +$helper->dump($res); +$helper->line(); + +$res = V8\JSON::parse($context, new V8\StringValue($isolate, '[]')); +$helper->dump($res); +$helper->line(); + +$res = V8\JSON::parse($context, new V8\StringValue($isolate, '{}')); +$helper->dump($res); +$helper->line(); + +try { + V8\JSON::parse($context, new V8\StringValue($isolate, '[123}')); +} catch (\V8\Exceptions\TryCatchException $e) { + $helper->exception_export($e); + $helper->line(); +} + +$helper->header('Stringify'); + +$res = V8\JSON::stringify($context, new V8\StringValue($isolate, 'test')); +$helper->dump($res); +$helper->line(); + +$obj_inner = new \V8\ObjectValue($context); +$obj_inner->set($context, new \V8\StringValue($isolate, 'bar'), new \V8\StringValue($isolate, 'baz')); +$obj = new \V8\ObjectValue($context); +$obj->set($context, new \V8\StringValue($isolate, 'foo'), $obj_inner); + + +$res = V8\JSON::stringify($context, $obj); +$helper->dump($res); +$helper->line(); + +$res = V8\JSON::stringify($context, $obj, new \V8\StringValue($isolate, ' ')); +$helper->dump($res); +$helper->line(); + + + +?> +--EXPECT-- +Parse: +------ +object(V8\StringValue)#6 (1) { + ["isolate":"V8\Value":private]=> + object(V8\Isolate)#3 (0) { + } +} + +object(V8\ArrayObject)#7 (2) { + ["isolate":"V8\Value":private]=> + object(V8\Isolate)#3 (0) { + } + ["context":"V8\ObjectValue":private]=> + object(V8\Context)#4 (1) { + ["isolate":"V8\Context":private]=> + object(V8\Isolate)#3 (0) { + } + } +} + +object(V8\ObjectValue)#5 (2) { + ["isolate":"V8\Value":private]=> + object(V8\Isolate)#3 (0) { + } + ["context":"V8\ObjectValue":private]=> + object(V8\Context)#4 (1) { + ["isolate":"V8\Context":private]=> + object(V8\Isolate)#3 (0) { + } + } +} + +V8\Exceptions\TryCatchException: SyntaxError: Unexpected token } in JSON at position 4 + +Stringify: +---------- +string(6) ""test"" + +string(21) "{"foo":{"bar":"baz"}}" + +string(43) "{ + "foo": { + "bar": "baz" + } +}" diff --git a/v8.cc b/v8.cc index a66e71e..077139e 100644 --- a/v8.cc +++ b/v8.cc @@ -66,6 +66,7 @@ #include "php_v8_function_callback_info.h" #include "php_v8_named_property_handler_configuration.h" #include "php_v8_indexed_property_handler_configuration.h" +#include "php_v8_json.h" #include "php_v8_value.h" #include "php_v8_data.h" @@ -167,6 +168,8 @@ PHP_MINIT_FUNCTION(v8) PHP_MINIT(php_v8_named_property_handler_configuration)(INIT_FUNC_ARGS_PASSTHRU); PHP_MINIT(php_v8_indexed_property_handler_configuration)(INIT_FUNC_ARGS_PASSTHRU); + PHP_MINIT(php_v8_json)(INIT_FUNC_ARGS_PASSTHRU); + /* If you have INI entries, uncomment these lines REGISTER_INI_ENTRIES(); */ From 7f3dc3e50ff1d8323df9c6881ededa3a3cbc18e1 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 18:46:05 +0300 Subject: [PATCH 12/17] Add Message::getErrorLevel() method, closes #52 --- src/php_v8_message.cc | 36 +++++++++++++++++-- stubs/src/Message.php | 24 ++++++++++++- tests/001-verify_extension_entities.phpt | 10 +++++- .../ExceptionManager_createCreateMessage.phpt | 6 ++-- tests/Message.phpt | 24 +++++++++++-- tests/TryCatch.phpt | 4 ++- 6 files changed, 94 insertions(+), 10 deletions(-) diff --git a/src/php_v8_message.cc b/src/php_v8_message.cc index ab4b81f..29d06c9 100644 --- a/src/php_v8_message.cc +++ b/src/php_v8_message.cc @@ -101,6 +101,8 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph if (v8::Message::kNoColumnInfo != end_column) { zend_update_property_long(this_ce, return_value, ZEND_STRL("end_column"), static_cast(end_column)); } + + zend_update_property_long(this_ce, return_value, ZEND_STRL("error_level"), static_cast(message->ErrorLevel())); } @@ -117,10 +119,11 @@ static PHP_METHOD(Message, __construct) { zend_long end_position = -1; zend_long start_column = -1; zend_long end_column = -1; + zend_long error_level = -1; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSoSo|lllll", + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SSoSo|llllll", &message, &source_line, &script_origin, &resource_name, &stack_trace, - &line_number, &start_position, &end_position, &start_column, &end_column) == FAILURE) { + &line_number, &start_position, &end_position, &start_column, &end_column, &error_level) == FAILURE) { return; } @@ -145,6 +148,9 @@ static PHP_METHOD(Message, __construct) { if (end_column > 0) { zend_update_property_long(this_ce, getThis(), ZEND_STRL("end_column"), end_column); } + if (end_column > 0) { + zend_update_property_long(this_ce, getThis(), ZEND_STRL("error_level"), error_level); + } } static PHP_METHOD(Message, get) @@ -257,6 +263,18 @@ static PHP_METHOD(Message, getEndColumn) RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("end_column"), 0, &rv), 1, 0); } +static PHP_METHOD(Message, getErrorLevel) +{ + zval rv; + + if (zend_parse_parameters_none() == FAILURE) { + return; + } + + RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("error_level"), 0, &rv), 1, 0); +} + + PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 5) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, source_line, IS_STRING, 0) @@ -268,6 +286,7 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_CONSTRUCTOR_INFO_EX(arginfo___construct, 5) ZEND_ARG_TYPE_INFO(0, end_position, IS_LONG, 1) ZEND_ARG_TYPE_INFO(0, start_column, IS_LONG, 1) ZEND_ARG_TYPE_INFO(0, end_column, IS_LONG, 1) + ZEND_ARG_TYPE_INFO(0, error_level, IS_LONG, 1) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get, ZEND_RETURN_VALUE, 0, IS_STRING, 0) @@ -300,6 +319,9 @@ ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getEndColumn, ZEND_RETURN_VALUE, 0, IS_LONG, 1) ZEND_END_ARG_INFO() +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_getErrorLevel, ZEND_RETURN_VALUE, 0, IS_LONG, 1) +ZEND_END_ARG_INFO() + static const zend_function_entry php_v8_message_methods[] = { PHP_V8_ME(Message, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) @@ -313,15 +335,24 @@ static const zend_function_entry php_v8_message_methods[] = { PHP_V8_ME(Message, getEndPosition, ZEND_ACC_PUBLIC) PHP_V8_ME(Message, getStartColumn, ZEND_ACC_PUBLIC) PHP_V8_ME(Message, getEndColumn, ZEND_ACC_PUBLIC) + PHP_V8_ME(Message, getErrorLevel, ZEND_ACC_PUBLIC) PHP_FE_END }; + PHP_MINIT_FUNCTION (php_v8_message) { zend_class_entry ce; INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "Message", php_v8_message_methods); this_ce = zend_register_internal_class(&ce); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ERROR_LEVEL_LOG"), v8::Isolate::MessageErrorLevel::kMessageLog); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ERROR_LEVEL_DEBUG"), v8::Isolate::MessageErrorLevel::kMessageDebug); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ERROR_LEVEL_INFO"), v8::Isolate::MessageErrorLevel::kMessageInfo); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ERROR_LEVEL_ERROR"), v8::Isolate::MessageErrorLevel::kMessageError); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ERROR_LEVEL_WARNING"), v8::Isolate::MessageErrorLevel::kMessageWarning); + zend_declare_class_constant_long(this_ce, ZEND_STRL("ERROR_LEVEL_ALL"), v8::Isolate::MessageErrorLevel::kMessageAll); + zend_declare_property_string(this_ce, ZEND_STRL("message"), "", ZEND_ACC_PRIVATE); zend_declare_property_null(this_ce, ZEND_STRL("script_origin"), ZEND_ACC_PRIVATE); zend_declare_property_string(this_ce, ZEND_STRL("source_line"), "", ZEND_ACC_PRIVATE); @@ -334,6 +365,7 @@ PHP_MINIT_FUNCTION (php_v8_message) { zend_declare_property_null(this_ce, ZEND_STRL("start_column"), ZEND_ACC_PRIVATE); zend_declare_property_null(this_ce, ZEND_STRL("end_column"), ZEND_ACC_PRIVATE); + zend_declare_property_null(this_ce, ZEND_STRL("error_level"), ZEND_ACC_PRIVATE); return SUCCESS; } diff --git a/stubs/src/Message.php b/stubs/src/Message.php index e746830..6ff88a2 100644 --- a/stubs/src/Message.php +++ b/stubs/src/Message.php @@ -20,6 +20,13 @@ */ class Message { + const ERROR_LEVEL_LOG = 1; + const ERROR_LEVEL_DEBUG = 2; + const ERROR_LEVEL_INFO = 4; + const ERROR_LEVEL_ERROR = 8; + const ERROR_LEVEL_WARNING = 16; + const ERROR_LEVEL_ALL = 31; + /** * @var ScriptOrigin */ @@ -60,6 +67,10 @@ class Message * @var int|null */ private $end_column; + /** + * @var int|null + */ + private $error_level; /** * @param string $message @@ -72,6 +83,7 @@ class Message * @param int $end_position * @param int $start_column * @param int $end_column + * @param int|null $error_level */ public function __construct( string $message, @@ -83,7 +95,8 @@ public function __construct( ?int $start_position = null, ?int $end_position = null, ?int $start_column = null, - ?int $end_column = null + ?int $end_column = null, + ?int $error_level = null ) { } @@ -181,4 +194,13 @@ public function getStartColumn(): ?int public function getEndColumn(): ?int { } + + /** + * Returns the error level of the message. + * + * @return int|null + */ + public function getErrorLevel(): ?int + { + } } diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index 8f77e81..be90c66 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -440,6 +440,12 @@ class V8\TryCatch public function getExternalException(): ?Throwable class V8\Message + const ERROR_LEVEL_LOG = 1 + const ERROR_LEVEL_DEBUG = 2 + const ERROR_LEVEL_INFO = 4 + const ERROR_LEVEL_ERROR = 8 + const ERROR_LEVEL_WARNING = 16 + const ERROR_LEVEL_ALL = 31 private $message private $script_origin private $source_line @@ -450,7 +456,8 @@ class V8\Message private $end_position private $start_column private $end_column - public function __construct(string $message, string $source_line, V8\ScriptOrigin $script_origin, string $resource_name, V8\StackTrace $stack_trace, ?int $line_number, ?int $start_position, ?int $end_position, ?int $start_column, ?int $end_column) + private $error_level + public function __construct(string $message, string $source_line, V8\ScriptOrigin $script_origin, string $resource_name, V8\StackTrace $stack_trace, ?int $line_number, ?int $start_position, ?int $end_position, ?int $start_column, ?int $end_column, ?int $error_level) public function get(): string public function getSourceLine(): string public function getScriptOrigin(): V8\ScriptOrigin @@ -461,6 +468,7 @@ class V8\Message public function getEndPosition(): ?int public function getStartColumn(): ?int public function getEndColumn(): ?int + public function getErrorLevel(): ?int class V8\StackFrame private $line_number diff --git a/tests/ExceptionManager_createCreateMessage.phpt b/tests/ExceptionManager_createCreateMessage.phpt index f1d3bee..3029b70 100644 --- a/tests/ExceptionManager_createCreateMessage.phpt +++ b/tests/ExceptionManager_createCreateMessage.phpt @@ -114,13 +114,14 @@ V8\Message->getStartPosition(): int(231) V8\Message->getEndPosition(): int(232) V8\Message->getStartColumn(): int(8) V8\Message->getEndColumn(): int(9) +V8\Message->getErrorLevel(): int(8) Message created from created value: ----------------------------------- V8\Message->get(): string(13) "Uncaught test" V8\Message->getSourceLine(): string(24) " test(exception);" V8\Message->getScriptOrigin(): - object(V8\ScriptOrigin)#33 (6) { + object(V8\ScriptOrigin)#34 (6) { ["resource_name":"V8\ScriptOrigin":private]=> string(7) "test.js" ["resource_line_offset":"V8\ScriptOrigin":private]=> @@ -132,7 +133,7 @@ V8\Message->getScriptOrigin(): ["source_map_url":"V8\ScriptOrigin":private]=> string(0) "" ["options":"V8\ScriptOrigin":private]=> - object(V8\ScriptOriginOptions)#32 (1) { + object(V8\ScriptOriginOptions)#33 (1) { ["flags":"V8\ScriptOriginOptions":private]=> int(0) } @@ -144,6 +145,7 @@ V8\Message->getStartPosition(): int(231) V8\Message->getEndPosition(): int(232) V8\Message->getStartColumn(): int(8) V8\Message->getEndColumn(): int(9) +V8\Message->getErrorLevel(): int(8) Checks on V8\ObjectValue: diff --git a/tests/Message.phpt b/tests/Message.phpt index 84fd922..d21b914 100644 --- a/tests/Message.phpt +++ b/tests/Message.phpt @@ -22,6 +22,10 @@ $helper->header('Object representation (default)'); $helper->dump($obj); $helper->space(); +$helper->header('Class constants'); +$helper->dump_object_constants($obj); +$helper->space(); + $helper->header('Test getters (default)'); $helper->method_matches_with_output($obj, 'get', 'message'); $helper->method_matches_with_output($obj, 'getSourceLine', 'source_line'); @@ -36,7 +40,7 @@ $helper->method_matches_with_output($obj, 'getEndColumn', null); $helper->space(); -$obj = new V8\Message('message', 'source_line', $origin, 'resource_name', $trace, 1, 2, 3, 4, 5); +$obj = new V8\Message('message', 'source_line', $origin, 'resource_name', $trace, 1, 2, 3, 4, 5, 7); $helper->header('Object representation'); $helper->dump($obj); @@ -59,7 +63,7 @@ $helper->space(); --EXPECT-- Object representation (default): -------------------------------- -object(V8\Message)#7 (10) { +object(V8\Message)#7 (11) { ["message":"V8\Message":private]=> string(7) "message" ["script_origin":"V8\Message":private]=> @@ -100,9 +104,21 @@ object(V8\Message)#7 (10) { NULL ["end_column":"V8\Message":private]=> NULL + ["error_level":"V8\Message":private]=> + NULL } +Class constants: +---------------- +V8\Message::ERROR_LEVEL_LOG = 1 +V8\Message::ERROR_LEVEL_DEBUG = 2 +V8\Message::ERROR_LEVEL_INFO = 4 +V8\Message::ERROR_LEVEL_ERROR = 8 +V8\Message::ERROR_LEVEL_WARNING = 16 +V8\Message::ERROR_LEVEL_ALL = 31 + + Test getters (default): ----------------------- V8\Message::get() matches expected 'message' @@ -119,7 +135,7 @@ V8\Message::getEndColumn() matches expected NULL Object representation: ---------------------- -object(V8\Message)#8 (10) { +object(V8\Message)#8 (11) { ["message":"V8\Message":private]=> string(7) "message" ["script_origin":"V8\Message":private]=> @@ -160,6 +176,8 @@ object(V8\Message)#8 (10) { int(4) ["end_column":"V8\Message":private]=> int(5) + ["error_level":"V8\Message":private]=> + int(7) } diff --git a/tests/TryCatch.phpt b/tests/TryCatch.phpt index 9163e3f..5719f09 100644 --- a/tests/TryCatch.phpt +++ b/tests/TryCatch.phpt @@ -142,7 +142,7 @@ object(V8\TryCatch)#11 (8) { } } ["message":"V8\TryCatch":private]=> - object(V8\Message)#6 (10) { + object(V8\Message)#6 (11) { ["message":"V8\Message":private]=> string(7) "message" ["script_origin":"V8\Message":private]=> @@ -183,6 +183,8 @@ object(V8\TryCatch)#11 (8) { NULL ["end_column":"V8\Message":private]=> NULL + ["error_level":"V8\Message":private]=> + NULL } ["can_continue":"V8\TryCatch":private]=> bool(true) From 3c84fe2ae103ce4addbe889b9a01d8a1ddeec1f4 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 18:55:00 +0300 Subject: [PATCH 13/17] Rename SymbolValue methods, #41 --- src/php_v8_symbol.cc | 56 ++++++++++----------- stubs/src/SymbolValue.php | 24 ++++----- tests/001-verify_extension_entities.phpt | 24 ++++----- tests/SymbolValue.phpt | 64 ++++++++++++------------ 4 files changed, 84 insertions(+), 84 deletions(-) diff --git a/src/php_v8_symbol.cc b/src/php_v8_symbol.cc index 143f125..506408b 100644 --- a/src/php_v8_symbol.cc +++ b/src/php_v8_symbol.cc @@ -91,7 +91,7 @@ static PHP_METHOD(Symbol, name) php_v8_get_or_create_value(return_value, local_name, php_v8_value->php_v8_isolate); } -static PHP_METHOD(Symbol, for) +static PHP_METHOD(Symbol, createFor) { zval *php_v8_context_zv; zval *php_v8_name_zv; @@ -115,7 +115,7 @@ static PHP_METHOD(Symbol, for) php_v8_get_or_create_value(return_value, local_symbol, php_v8_context->php_v8_isolate); } -static PHP_METHOD(Symbol, forApi) +static PHP_METHOD(Symbol, createForApi) { zval *php_v8_context_zv; zval *php_v8_name_zv; @@ -142,7 +142,7 @@ static PHP_METHOD(Symbol, forApi) // Well-known symbols #define PHP_V8_SYMBOL_WELL_KNOWN_METHOD(classname, name) \ - PHP_METHOD(classname, get##name) \ + PHP_METHOD(classname, get##name##Symbol) \ { \ zval *php_v8_isolate_zv; \ \ @@ -183,52 +183,52 @@ ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_name, ZEND_RETURN_VALUE, 0, V8\\Value, 0) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_for, ZEND_RETURN_VALUE, 2, V8\\SymbolValue, 0) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_createFor, ZEND_RETURN_VALUE, 2, V8\\SymbolValue, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) ZEND_ARG_OBJ_INFO(0, name, V8\\StringValue, 0) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_forApi, ZEND_RETURN_VALUE, 2, V8\\SymbolValue, 0) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_createForApi, ZEND_RETURN_VALUE, 2, V8\\SymbolValue, 0) ZEND_ARG_OBJ_INFO(0, context, V8\\Context, 0) ZEND_ARG_OBJ_INFO(0, name, V8\\StringValue, 0) ZEND_END_ARG_INFO() #define PHP_V8_SYMBOL_WELL_KNOWN_ARGS(name) \ - PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) \ + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_##name##Symbol, ZEND_RETURN_VALUE, 1, V8\\SymbolValue, 0) \ ZEND_ARG_OBJ_INFO(0, isolate, V8\\Isolate, 0) \ ZEND_END_ARG_INFO() \ // Well-known symbols -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getHasInstance); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getIsConcatSpreadable); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getIterator); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getMatch); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getReplace); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getSearch); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getSplit); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getToPrimitive); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getToStringTag); -PHP_V8_SYMBOL_WELL_KNOWN_ARGS(arginfo_getUnscopables); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getHasInstance); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getIsConcatSpreadable); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getIterator); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getMatch); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getReplace); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getSearch); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getSplit); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getToPrimitive); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getToStringTag); +PHP_V8_SYMBOL_WELL_KNOWN_ARGS(getUnscopables); static const zend_function_entry php_v8_symbol_methods[] = { PHP_V8_ME(Symbol, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_V8_ME(Symbol, value, ZEND_ACC_PUBLIC) PHP_V8_ME(Symbol, name, ZEND_ACC_PUBLIC) - PHP_V8_ME(Symbol, for, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, forApi, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, createFor, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, createForApi, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) // Well-known symbols - PHP_V8_ME(Symbol, getHasInstance, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getIsConcatSpreadable, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getIterator, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getMatch, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getReplace, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getSearch, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getSplit, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getToPrimitive, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getToStringTag, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_V8_ME(Symbol, getUnscopables, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getHasInstanceSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getIsConcatSpreadableSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getIteratorSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getMatchSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getReplaceSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getSearchSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getSplitSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getToPrimitiveSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getToStringTagSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_V8_ME(Symbol, getUnscopablesSymbol, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) PHP_FE_END }; diff --git a/stubs/src/SymbolValue.php b/stubs/src/SymbolValue.php index 322d76f..44cfbd1 100644 --- a/stubs/src/SymbolValue.php +++ b/stubs/src/SymbolValue.php @@ -63,7 +63,7 @@ public function name(): Value * * @return SymbolValue */ - public static function for(Context $context, StringValue $name): SymbolValue + public static function createFor(Context $context, StringValue $name): SymbolValue { } @@ -78,7 +78,7 @@ public static function for(Context $context, StringValue $name): SymbolValue * * @return SymbolValue */ - public static function forApi(Context $context, StringValue $name): SymbolValue + public static function createForApi(Context $context, StringValue $name): SymbolValue { } @@ -89,7 +89,7 @@ public static function forApi(Context $context, StringValue $name): SymbolValue * * @return SymbolValue */ - public static function getHasInstance(Isolate $isolate): SymbolValue + public static function getHasInstanceSymbol(Isolate $isolate): SymbolValue { } @@ -98,7 +98,7 @@ public static function getHasInstance(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getIsConcatSpreadable(Isolate $isolate): SymbolValue + public static function getIsConcatSpreadableSymbol(Isolate $isolate): SymbolValue { } @@ -107,7 +107,7 @@ public static function getIsConcatSpreadable(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getIterator(Isolate $isolate): SymbolValue + public static function getIteratorSymbol(Isolate $isolate): SymbolValue { } @@ -116,7 +116,7 @@ public static function getIterator(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getMatch(Isolate $isolate): SymbolValue + public static function getMatchSymbol(Isolate $isolate): SymbolValue { } @@ -125,7 +125,7 @@ public static function getMatch(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getReplace(Isolate $isolate): SymbolValue + public static function getReplaceSymbol(Isolate $isolate): SymbolValue { } @@ -134,7 +134,7 @@ public static function getReplace(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getSearch(Isolate $isolate): SymbolValue + public static function getSearchSymbol(Isolate $isolate): SymbolValue { } @@ -143,7 +143,7 @@ public static function getSearch(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getSplit(Isolate $isolate): SymbolValue + public static function getSplitSymbol(Isolate $isolate): SymbolValue { } @@ -152,7 +152,7 @@ public static function getSplit(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getToPrimitive(Isolate $isolate): SymbolValue + public static function getToPrimitiveSymbol(Isolate $isolate): SymbolValue { } @@ -161,7 +161,7 @@ public static function getToPrimitive(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getToStringTag(Isolate $isolate): SymbolValue + public static function getToStringTagSymbol(Isolate $isolate): SymbolValue { } @@ -170,7 +170,7 @@ public static function getToStringTag(Isolate $isolate): SymbolValue * * @return SymbolValue */ - public static function getUnscopables(Isolate $isolate): SymbolValue + public static function getUnscopablesSymbol(Isolate $isolate): SymbolValue { } } diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index be90c66..6c4bdb0 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -640,18 +640,18 @@ class V8\SymbolValue public function __construct(V8\Isolate $isolate, ?V8\StringValue $name) public function value(): string public function name(): V8\Value - public static function for(V8\Context $context, V8\StringValue $name): V8\SymbolValue - public static function forApi(V8\Context $context, V8\StringValue $name): V8\SymbolValue - public static function getHasInstance(V8\Isolate $isolate): V8\SymbolValue - public static function getIsConcatSpreadable(V8\Isolate $isolate): V8\SymbolValue - public static function getIterator(V8\Isolate $isolate): V8\SymbolValue - public static function getMatch(V8\Isolate $isolate): V8\SymbolValue - public static function getReplace(V8\Isolate $isolate): V8\SymbolValue - public static function getSearch(V8\Isolate $isolate): V8\SymbolValue - public static function getSplit(V8\Isolate $isolate): V8\SymbolValue - public static function getToPrimitive(V8\Isolate $isolate): V8\SymbolValue - public static function getToStringTag(V8\Isolate $isolate): V8\SymbolValue - public static function getUnscopables(V8\Isolate $isolate): V8\SymbolValue + public static function createFor(V8\Context $context, V8\StringValue $name): V8\SymbolValue + public static function createForApi(V8\Context $context, V8\StringValue $name): V8\SymbolValue + public static function getHasInstanceSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getIsConcatSpreadableSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getIteratorSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getMatchSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getReplaceSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getSearchSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getSplitSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getToPrimitiveSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getToStringTagSymbol(V8\Isolate $isolate): V8\SymbolValue + public static function getUnscopablesSymbol(V8\Isolate $isolate): V8\SymbolValue class V8\NumberValue extends V8\PrimitiveValue diff --git a/tests/SymbolValue.phpt b/tests/SymbolValue.phpt index 8590cf0..4725d05 100644 --- a/tests/SymbolValue.phpt +++ b/tests/SymbolValue.phpt @@ -123,7 +123,7 @@ $v8_helper->run_checks($res, 'Checkers on Symbol value from script'); function test_For(\V8\Context $context, PhpV8Testsuite $helper) { - $value = V8\SymbolValue::for($context, new \V8\StringValue($context->getIsolate(), 'test')); + $value = V8\SymbolValue::createFor($context, new \V8\StringValue($context->getIsolate(), 'test')); $helper->assert('Symbol For(string) returned', $value instanceof \V8\SymbolValue); $helper->pretty_dump('Symbol For(string) name', $value->name()->value()); $helper->line(); @@ -146,22 +146,22 @@ $v8_helper->CompileRun($context, 'test_For()'); $helper->assert('Isolate not in context', !$isolate->inContext()); -$value = V8\SymbolValue::forApi($context, new \V8\StringValue($isolate, 'test')); +$value = V8\SymbolValue::createForApi($context, new \V8\StringValue($isolate, 'test')); $helper->assert('Symbol ForApi(string) returned', $value instanceof \V8\SymbolValue); $helper->pretty_dump('Symbol ForApi(string) name', $value->name()->value()); $helper->line(); $static_getters = [ - 'GetHasInstance', - 'GetIsConcatSpreadable', - 'GetIterator', - 'GetMatch', - 'GetReplace', - 'GetSearch', - 'GetSplit', - 'GetToPrimitive', - 'GetToStringTag', - 'GetUnscopables', + 'getHasInstanceSymbol', + 'getIsConcatSpreadableSymbol', + 'getIteratorSymbol', + 'getMatchSymbol', + 'getReplaceSymbol', + 'getSearchSymbol', + 'getSplitSymbol', + 'getToPrimitiveSymbol', + 'getToStringTagSymbol', + 'getUnscopablesSymbol', ]; foreach ($static_getters as $static_getter) { @@ -607,41 +607,41 @@ Symbol ForApi(string) returned: ok Symbol ForApi(string) name: string(4) "test" Isolate not in context: ok -Symbol GetHasInstance() returned: ok -Symbol GetHasInstance() name: string(18) "Symbol.hasInstance" +Symbol getHasInstanceSymbol() returned: ok +Symbol getHasInstanceSymbol() name: string(18) "Symbol.hasInstance" Isolate not in context: ok -Symbol GetIsConcatSpreadable() returned: ok -Symbol GetIsConcatSpreadable() name: string(25) "Symbol.isConcatSpreadable" +Symbol getIsConcatSpreadableSymbol() returned: ok +Symbol getIsConcatSpreadableSymbol() name: string(25) "Symbol.isConcatSpreadable" Isolate not in context: ok -Symbol GetIterator() returned: ok -Symbol GetIterator() name: string(15) "Symbol.iterator" +Symbol getIteratorSymbol() returned: ok +Symbol getIteratorSymbol() name: string(15) "Symbol.iterator" Isolate not in context: ok -Symbol GetMatch() returned: ok -Symbol GetMatch() name: string(12) "Symbol.match" +Symbol getMatchSymbol() returned: ok +Symbol getMatchSymbol() name: string(12) "Symbol.match" Isolate not in context: ok -Symbol GetReplace() returned: ok -Symbol GetReplace() name: string(14) "Symbol.replace" +Symbol getReplaceSymbol() returned: ok +Symbol getReplaceSymbol() name: string(14) "Symbol.replace" Isolate not in context: ok -Symbol GetSearch() returned: ok -Symbol GetSearch() name: string(13) "Symbol.search" +Symbol getSearchSymbol() returned: ok +Symbol getSearchSymbol() name: string(13) "Symbol.search" Isolate not in context: ok -Symbol GetSplit() returned: ok -Symbol GetSplit() name: string(12) "Symbol.split" +Symbol getSplitSymbol() returned: ok +Symbol getSplitSymbol() name: string(12) "Symbol.split" Isolate not in context: ok -Symbol GetToPrimitive() returned: ok -Symbol GetToPrimitive() name: string(18) "Symbol.toPrimitive" +Symbol getToPrimitiveSymbol() returned: ok +Symbol getToPrimitiveSymbol() name: string(18) "Symbol.toPrimitive" Isolate not in context: ok -Symbol GetToStringTag() returned: ok -Symbol GetToStringTag() name: string(18) "Symbol.toStringTag" +Symbol getToStringTagSymbol() returned: ok +Symbol getToStringTagSymbol() name: string(18) "Symbol.toStringTag" Isolate not in context: ok -Symbol GetUnscopables() returned: ok -Symbol GetUnscopables() name: string(18) "Symbol.unscopables" +Symbol getUnscopablesSymbol() returned: ok +Symbol getUnscopablesSymbol() name: string(18) "Symbol.unscopables" From babba44f81ba6e8ae674becfb4728dbaab7a8649 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 19:04:28 +0300 Subject: [PATCH 14/17] Rename TryCatch methods, #41 --- src/php_v8_try_catch.cc | 18 +++++++------- stubs/src/TryCatch.php | 21 +++------------- tests/001-verify_extension_entities.phpt | 6 ++--- .../Isolate_throwException_with_external.phpt | 2 +- tests/TryCatch.phpt | 24 +++++++++---------- tests/TryCatch_from_script.phpt | 12 +++++----- 6 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/php_v8_try_catch.cc b/src/php_v8_try_catch.cc index 4467fb2..60feb40 100644 --- a/src/php_v8_try_catch.cc +++ b/src/php_v8_try_catch.cc @@ -151,7 +151,7 @@ static PHP_METHOD(TryCatch, getContext) RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("context"), 0, &rv), 1, 0); } -static PHP_METHOD(TryCatch, exception) +static PHP_METHOD(TryCatch, getException) { zval rv; zval *prop; @@ -165,7 +165,7 @@ static PHP_METHOD(TryCatch, exception) RETVAL_ZVAL(prop, 1, 0); } -static PHP_METHOD(TryCatch, stackTrace) +static PHP_METHOD(TryCatch, getStackTrace) { zval rv; zval *prop; @@ -179,7 +179,7 @@ static PHP_METHOD(TryCatch, stackTrace) RETVAL_ZVAL(prop, 1, 0); } -static PHP_METHOD(TryCatch, message) +static PHP_METHOD(TryCatch, getMessage) { zval rv; zval *prop; @@ -245,13 +245,13 @@ ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getContext, ZEND_RETURN_VALUE, 0, V8\\Context, 0) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_exception, ZEND_RETURN_VALUE, 0, V8\\Value, 1) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getException, ZEND_RETURN_VALUE, 0, V8\\Value, 1) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_stackTrace, ZEND_RETURN_VALUE, 0, V8\\Value, 1) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getStackTrace, ZEND_RETURN_VALUE, 0, V8\\Value, 1) ZEND_END_ARG_INFO() -PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_message, ZEND_RETURN_VALUE, 0, V8\\Message, 1) +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_getMessage, ZEND_RETURN_VALUE, 0, V8\\Message, 1) ZEND_END_ARG_INFO() PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_canContinue, ZEND_RETURN_VALUE, 0, _IS_BOOL, 0) @@ -268,9 +268,9 @@ static const zend_function_entry php_v8_try_catch_methods[] = { PHP_V8_ME(TryCatch, __construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) PHP_V8_ME(TryCatch, getIsolate, ZEND_ACC_PUBLIC) PHP_V8_ME(TryCatch, getContext, ZEND_ACC_PUBLIC) - PHP_V8_ME(TryCatch, exception, ZEND_ACC_PUBLIC) - PHP_V8_ME(TryCatch, stackTrace, ZEND_ACC_PUBLIC) - PHP_V8_ME(TryCatch, message, ZEND_ACC_PUBLIC) + PHP_V8_ME(TryCatch, getException, ZEND_ACC_PUBLIC) + PHP_V8_ME(TryCatch, getStackTrace, ZEND_ACC_PUBLIC) + PHP_V8_ME(TryCatch, getMessage, ZEND_ACC_PUBLIC) PHP_V8_ME(TryCatch, canContinue, ZEND_ACC_PUBLIC) PHP_V8_ME(TryCatch, hasTerminated, ZEND_ACC_PUBLIC) diff --git a/stubs/src/TryCatch.php b/stubs/src/TryCatch.php index a1127f8..52e1874 100644 --- a/stubs/src/TryCatch.php +++ b/stubs/src/TryCatch.php @@ -79,13 +79,6 @@ public function __construct( bool $has_terminated = false, Throwable $external_exception = null ) { - $this->isolate = $isolate; - $this->exception = $exception; - $this->stack_trace = $stack_trace; - $this->message = $message; - $this->can_continue = $can_continue; - $this->has_terminated = $has_terminated; - $this->external_exception = $external_exception; } /** @@ -93,7 +86,6 @@ public function __construct( */ public function getIsolate(): Isolate { - return $this->isolate; } /** @@ -101,7 +93,6 @@ public function getIsolate(): Isolate */ public function getContext(): Context { - return $this->context; } /** @@ -113,9 +104,8 @@ public function getContext(): Context * @return Value|null * */ - public function exception(): ?Value + public function getException(): ?Value { - return $this->exception; } /** @@ -124,9 +114,8 @@ public function exception(): ?Value * * @return Value|null */ - public function stackTrace(): ?Value + public function getStackTrace(): ?Value { - return $this->stack_trace; } /** @@ -138,9 +127,8 @@ public function stackTrace(): ?Value * * @return Message|null */ - public function message(): ?Message + public function getMessage(): ?Message { - return $this->message; } /** @@ -155,7 +143,6 @@ public function message(): ?Message */ public function canContinue(): bool { - return $this->can_continue; } /** @@ -174,7 +161,6 @@ public function canContinue(): bool */ public function hasTerminated(): bool { - return $this->has_terminated; } /** @@ -182,6 +168,5 @@ public function hasTerminated(): bool */ public function getExternalException(): ?Throwable { - return $this->external_exception; } } diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index 6c4bdb0..c59878b 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -432,9 +432,9 @@ class V8\TryCatch public function __construct(V8\Isolate $isolate, V8\Context $context, ?V8\Value $exception, ?V8\Value $stack_trace, ?V8\Message $message, bool $can_continue, bool $has_terminated, ?Throwable $external_exception) public function getIsolate(): V8\Isolate public function getContext(): V8\Context - public function exception(): ?V8\Value - public function stackTrace(): ?V8\Value - public function message(): ?V8\Message + public function getException(): ?V8\Value + public function getStackTrace(): ?V8\Value + public function getMessage(): ?V8\Message public function canContinue(): bool public function hasTerminated(): bool public function getExternalException(): ?Throwable diff --git a/tests/Isolate_throwException_with_external.phpt b/tests/Isolate_throwException_with_external.phpt index 0645a8e..7592e14 100644 --- a/tests/Isolate_throwException_with_external.phpt +++ b/tests/Isolate_throwException_with_external.phpt @@ -41,7 +41,7 @@ try { } catch (\V8\Exceptions\TryCatchException $e) { $helper->exception_export($e); - $helper->assert('Thrown exception object is the same', $e->getTryCatch()->exception(), $v8_exception); + $helper->assert('Thrown exception object is the same', $e->getTryCatch()->getException(), $v8_exception); $helper->exception_export($e->getTryCatch()->getExternalException()); } diff --git a/tests/TryCatch.phpt b/tests/TryCatch.phpt index 5719f09..8b2baa5 100644 --- a/tests/TryCatch.phpt +++ b/tests/TryCatch.phpt @@ -26,9 +26,9 @@ $helper->space(); $helper->header('Test getters (default)'); $helper->method_matches($obj, 'getIsolate', $isolate); $helper->method_matches($obj, 'getContext', $context); -$helper->method_matches($obj, 'exception', null); -$helper->method_matches($obj, 'message', null); -$helper->method_matches($obj, 'stackTrace', null); +$helper->method_matches($obj, 'getException', null); +$helper->method_matches($obj, 'getMessage', null); +$helper->method_matches($obj, 'getStackTrace', null); $helper->method_matches($obj, 'canContinue', false); $helper->method_matches($obj, 'hasTerminated', false); @@ -49,9 +49,9 @@ $helper->space(); $helper->header('Test getters'); $helper->method_matches($obj, 'getIsolate', $isolate); $helper->method_matches($obj, 'getContext', $context); -$helper->method_matches($obj, 'exception', $exception); -$helper->method_matches($obj, 'message', $message); -$helper->method_matches($obj, 'stackTrace', $trace); +$helper->method_matches($obj, 'getException', $exception); +$helper->method_matches($obj, 'getMessage', $message); +$helper->method_matches($obj, 'getStackTrace', $trace); $helper->method_matches($obj, 'canContinue', true); $helper->method_matches($obj, 'hasTerminated', true); @@ -104,9 +104,9 @@ Test getters (default): ----------------------- V8\TryCatch::getIsolate() matches expected value V8\TryCatch::getContext() matches expected value -V8\TryCatch::exception() matches expected value -V8\TryCatch::message() matches expected value -V8\TryCatch::stackTrace() matches expected value +V8\TryCatch::getException() matches expected value +V8\TryCatch::getMessage() matches expected value +V8\TryCatch::getStackTrace() matches expected value V8\TryCatch::canContinue() matches expected value V8\TryCatch::hasTerminated() matches expected value @@ -215,9 +215,9 @@ Test getters: ------------- V8\TryCatch::getIsolate() matches expected value V8\TryCatch::getContext() matches expected value -V8\TryCatch::exception() matches expected value -V8\TryCatch::message() matches expected value -V8\TryCatch::stackTrace() matches expected value +V8\TryCatch::getException() matches expected value +V8\TryCatch::getMessage() matches expected value +V8\TryCatch::getStackTrace() matches expected value V8\TryCatch::canContinue() matches expected value V8\TryCatch::hasTerminated() matches expected value V8\TryCatch::getExternalException() matches expected value diff --git a/tests/TryCatch_from_script.phpt b/tests/TryCatch_from_script.phpt index 2ccc2ab..4ffb92c 100644 --- a/tests/TryCatch_from_script.phpt +++ b/tests/TryCatch_from_script.phpt @@ -44,7 +44,7 @@ $nested_try_catch_func_tpl = new \v8Tests\TrackingDtors\FunctionTemplate($isolat $helper->assert('TryCatch holds the same isolate it was thrown', $try_catch->getIsolate(), $isolate); $helper->assert('TryCatch holds the same context it was thrown', $try_catch->getContext(), $nested_context); - $helper->dump($e->getTryCatch()->message()->get()); + $helper->dump($e->getTryCatch()->getMessage()->get()); $helper->line(); } }); @@ -72,10 +72,10 @@ try { $helper->assert('TryCatch holds the same isolate it was thrown', $try_catch->getIsolate(), $script->getIsolate()); $helper->assert('TryCatch holds the same context it was thrown', $try_catch->getContext(), $script->getContext()); - $helper->dump($e->getTryCatch()->message()->get()); + $helper->dump($e->getTryCatch()->getMessage()->get()); $helper->line(); - $helper->assert('TryCatchException message has not stack trace', $e->getTryCatch()->message()->getStackTrace() === null); + $helper->assert('TryCatchException message has not stack trace', $e->getTryCatch()->getMessage()->getStackTrace() === null); $helper->line(); } @@ -87,7 +87,7 @@ try { $helper->exception_export($e); $helper->line(); - $helper->assert('TryCatchException message has stack trace', $e->getTryCatch()->message()->getStackTrace() instanceof \V8\StackTrace); + $helper->assert('TryCatchException message has stack trace', $e->getTryCatch()->getMessage()->getStackTrace() instanceof \V8\StackTrace); $helper->line(); } @@ -115,7 +115,7 @@ try { $helper->assert('TryCatch holds the same isolate it was thrown', $try_catch->getIsolate(), $script->getIsolate()); $helper->assert('TryCatch holds the same context it was thrown', $try_catch->getContext(), $script->getContext()); - $helper->dump($e->getTryCatch()->message()->get()); + $helper->dump($e->getTryCatch()->getMessage()->get()); $helper->line(); } @@ -129,7 +129,7 @@ try { $helper->assert('TryCatchException holds the same context it was thrown', $e->getContext(), $context); $helper->assert('TryCatchException holds the same isolate it was thrown', $e->getIsolate(), $isolate); - $helper->dump($e->getTryCatch()->message()->get()); + $helper->dump($e->getTryCatch()->getMessage()->get()); $helper->line(); } From a05c67a908953de974944cc7af19fa4573b97126 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 19:08:22 +0300 Subject: [PATCH 15/17] Add missed PrimitiveValue::value() abstract method --- src/php_v8_primitive.cc | 7 ++++++- tests/001-verify_extension_entities.phpt | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/php_v8_primitive.cc b/src/php_v8_primitive.cc index 30601ad..308f6da 100644 --- a/src/php_v8_primitive.cc +++ b/src/php_v8_primitive.cc @@ -22,8 +22,13 @@ zend_class_entry* php_v8_primitive_class_entry; #define this_ce php_v8_primitive_class_entry +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_value, 0) +ZEND_END_ARG_INFO() + + static const zend_function_entry php_v8_primitive_methods[] = { - PHP_FE_END + PHP_V8_ABSTRACT_ME(PrimitiveValue, value) + PHP_FE_END }; diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index c59878b..5152f5c 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -605,6 +605,7 @@ abstract class V8\Value abstract class V8\PrimitiveValue extends V8\Value + abstract public function value() class V8\UndefinedValue extends V8\PrimitiveValue From 3049be1b3d99f8edc05edb775e144c09eebb3736 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 19:13:19 +0300 Subject: [PATCH 16/17] Cleanup stubs in ScriptCompiler namespace [skip ci] --- stubs/src/ScriptCompiler/CachedData.php | 17 ++++++++++++----- stubs/src/ScriptCompiler/CompileOptions.php | 14 -------------- stubs/src/ScriptCompiler/Source.php | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 19 deletions(-) delete mode 100644 stubs/src/ScriptCompiler/CompileOptions.php diff --git a/stubs/src/ScriptCompiler/CachedData.php b/stubs/src/ScriptCompiler/CachedData.php index 9f303de..1049b6f 100644 --- a/stubs/src/ScriptCompiler/CachedData.php +++ b/stubs/src/ScriptCompiler/CachedData.php @@ -1,5 +1,17 @@ + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + namespace V8\ScriptCompiler; @@ -21,11 +33,6 @@ public function getData(): string { } - // TODO: technically, we can use \strlen($this->getData()) when we need, though in PHP it's not necessary to get string length before fetching string itself - //public function getLength(): int - //{ - //} - public function isRejected(): bool { } diff --git a/stubs/src/ScriptCompiler/CompileOptions.php b/stubs/src/ScriptCompiler/CompileOptions.php deleted file mode 100644 index 81cef9d..0000000 --- a/stubs/src/ScriptCompiler/CompileOptions.php +++ /dev/null @@ -1,14 +0,0 @@ - + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + namespace V8\ScriptCompiler; + use V8\ScriptOrigin; use V8\StringValue; From f780fe970dbaf8079478a927f067453d05aea5f6 Mon Sep 17 00:00:00 2001 From: Bogdan Padalko Date: Sun, 17 Sep 2017 20:09:31 +0300 Subject: [PATCH 17/17] Add Isolate::SetRAILMode(), closes #60 --- src/php_v8_enums.cc | 13 +++++++ src/php_v8_enums.h | 8 ++--- src/php_v8_isolate.cc | 21 +++++++++++ src/php_v8_isolate.h | 7 ++++ stubs/src/AccessControl.php | 2 +- stubs/src/ConstructorBehavior.php | 2 +- stubs/src/IntegrityLevel.php | 2 +- stubs/src/Isolate.php | 15 ++++++++ stubs/src/KeyCollectionMode.php | 2 +- stubs/src/PropertyAttribute.php | 2 +- stubs/src/PropertyFilter.php | 2 +- stubs/src/PropertyHandlerFlags.php | 2 +- stubs/src/RAILMode.php | 44 ++++++++++++++++++++++++ tests/001-verify_extension_entities.phpt | 7 ++++ tests/Isolate.phpt | 40 ++++++++++++++++++++- 15 files changed, 157 insertions(+), 12 deletions(-) create mode 100644 stubs/src/RAILMode.php diff --git a/src/php_v8_enums.cc b/src/php_v8_enums.cc index 6b9110d..d72e8f3 100644 --- a/src/php_v8_enums.cc +++ b/src/php_v8_enums.cc @@ -25,6 +25,7 @@ zend_class_entry* php_v8_property_handler_flags_class_entry; zend_class_entry *php_v8_property_filter_class_entry; zend_class_entry *php_v8_key_collection_mode_class_entry; zend_class_entry *php_v8_index_filter_class_entry; +zend_class_entry *php_v8_rail_mode_class_entry; static const zend_function_entry php_v8_enum_methods[] = { @@ -126,5 +127,17 @@ PHP_MINIT_FUNCTION (php_v8_enums) { zend_declare_class_constant_long(this_ce, ZEND_STRL("SKIP_INDICES"), static_cast(v8::IndexFilter::kSkipIndices)); #undef this_ce + // v8::RAILMode + #define this_ce php_v8_index_filter_class_entry + INIT_NS_CLASS_ENTRY(ce, PHP_V8_NS, "RAILMode", php_v8_enum_methods); + this_ce = zend_register_internal_class(&ce); + this_ce->ce_flags |= ZEND_ACC_FINAL; + + zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_RESPONSE"), static_cast(v8::RAILMode::PERFORMANCE_RESPONSE)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_ANIMATION"), static_cast(v8::RAILMode::PERFORMANCE_ANIMATION)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_IDLE"), static_cast(v8::RAILMode::PERFORMANCE_IDLE)); + zend_declare_class_constant_long(this_ce, ZEND_STRL("PERFORMANCE_LOAD"), static_cast(v8::RAILMode::PERFORMANCE_LOAD)); + #undef this_ce + return SUCCESS; } diff --git a/src/php_v8_enums.h b/src/php_v8_enums.h index c3922b1..6d57be3 100644 --- a/src/php_v8_enums.h +++ b/src/php_v8_enums.h @@ -31,6 +31,7 @@ extern zend_class_entry* php_v8_property_handler_flags_class_entry; extern zend_class_entry* php_v8_property_filter_class_entry; extern zend_class_entry* php_v8_key_collection_mode_class_entry; extern zend_class_entry* php_v8_index_filter_class_entry; +extern zend_class_entry *php_v8_rail_mode_class_entry; #define PHP_V8_ACCESS_CONTROL_FLAGS ( 0 \ @@ -77,12 +78,11 @@ extern zend_class_entry* php_v8_index_filter_class_entry; | static_cast(v8::KeyCollectionMode::kIncludePrototypes) \ ) -#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \ - | static_cast(v8::IndexFilter::kIncludeIndices) \ - | static_cast(v8::IndexFilter::kSkipIndices) \ +#define PHP_V8_INDEX_FILTER_FLAGS ( 0 \ + | static_cast(v8::IndexFilter::kIncludeIndices) \ + | static_cast(v8::IndexFilter::kSkipIndices) \ ) - PHP_MINIT_FUNCTION (php_v8_enums); #endif //PHP_V8_ENUMS_H diff --git a/src/php_v8_isolate.cc b/src/php_v8_isolate.cc index eb112d1..7c10b78 100644 --- a/src/php_v8_isolate.cc +++ b/src/php_v8_isolate.cc @@ -23,6 +23,7 @@ #include "php_v8_stack_trace.h" #include "php_v8_object.h" #include "php_v8_value.h" +#include "php_v8_enums.h" #include "php_v8_a.h" #include "php_v8.h" @@ -424,6 +425,21 @@ static PHP_METHOD(Isolate, lowMemoryNotification) { isolate->LowMemoryNotification(); } +static PHP_METHOD(Isolate, setRAILMode) { + zend_long rail_mode = -1; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &rail_mode) == FAILURE) { + return; + } + + PHP_V8_CHECK_ISOLATE_RAIL_MODE(rail_mode, "Invalid RAIL mode given. See V8\\RAILMode class constants for available values.") + + PHP_V8_ISOLATE_FETCH_WITH_CHECK(getThis(), php_v8_isolate); + PHP_V8_ENTER_ISOLATE(php_v8_isolate); + + isolate->SetRAILMode(static_cast(rail_mode)); +} + static PHP_METHOD(Isolate, terminateExecution) { if (zend_parse_parameters_none() == FAILURE) { return; @@ -549,6 +565,10 @@ PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_idleNotificationDeadline, ZEND_ARG_INFO(0, deadline_in_seconds) ZEND_END_ARG_INFO() +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_setRAILMode, 1) + ZEND_ARG_TYPE_INFO(0, rail_mode, IS_LONG, 0) +ZEND_END_ARG_INFO() + PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_VOID_INFO_EX(arginfo_lowMemoryNotification, 0) ZEND_END_ARG_INFO() @@ -588,6 +608,7 @@ static const zend_function_entry php_v8_isolate_methods[] = { PHP_V8_ME(Isolate, throwException, ZEND_ACC_PUBLIC) PHP_V8_ME(Isolate, idleNotificationDeadline, ZEND_ACC_PUBLIC) PHP_V8_ME(Isolate, lowMemoryNotification, ZEND_ACC_PUBLIC) + PHP_V8_ME(Isolate, setRAILMode, ZEND_ACC_PUBLIC) PHP_V8_ME(Isolate, terminateExecution, ZEND_ACC_PUBLIC) PHP_V8_ME(Isolate, isExecutionTerminating, ZEND_ACC_PUBLIC) PHP_V8_ME(Isolate, cancelTerminateExecution, ZEND_ACC_PUBLIC) diff --git a/src/php_v8_isolate.h b/src/php_v8_isolate.h index 244d864..6582783 100644 --- a/src/php_v8_isolate.h +++ b/src/php_v8_isolate.h @@ -122,6 +122,13 @@ inline v8::Local php_v8_isolate_get_key_local(php_v8_isolate_t *php return; \ } +#define PHP_V8_CHECK_ISOLATE_RAIL_MODE(mode, message) \ + if (mode < static_cast(v8::RAILMode::PERFORMANCE_RESPONSE) \ + || mode > static_cast(v8::RAILMode::PERFORMANCE_LOAD)) { \ + PHP_V8_THROW_VALUE_EXCEPTION(message); \ + return; \ + } + struct _php_v8_isolate_t { v8::Isolate *isolate; diff --git a/stubs/src/AccessControl.php b/stubs/src/AccessControl.php index 47c200a..469293c 100644 --- a/stubs/src/AccessControl.php +++ b/stubs/src/AccessControl.php @@ -15,7 +15,7 @@ namespace V8; -class AccessControl +final class AccessControl { const DEFAULT_ACCESS = 0; // do not allow cross-context access const ALL_CAN_READ = 1; // all cross-context reads are allowed diff --git a/stubs/src/ConstructorBehavior.php b/stubs/src/ConstructorBehavior.php index 6dd082d..055e1a6 100644 --- a/stubs/src/ConstructorBehavior.php +++ b/stubs/src/ConstructorBehavior.php @@ -16,7 +16,7 @@ namespace V8; -class ConstructorBehavior +final class ConstructorBehavior { const THROW = 0; const ALLOW = 1; diff --git a/stubs/src/IntegrityLevel.php b/stubs/src/IntegrityLevel.php index c016052..3790869 100644 --- a/stubs/src/IntegrityLevel.php +++ b/stubs/src/IntegrityLevel.php @@ -18,7 +18,7 @@ /** * Integrity level for objects. */ -class IntegrityLevel +final class IntegrityLevel { const FROZEN = 0; const SEALED = 1; diff --git a/stubs/src/Isolate.php b/stubs/src/Isolate.php index 4079b4a..8043d50 100644 --- a/stubs/src/Isolate.php +++ b/stubs/src/Isolate.php @@ -188,6 +188,21 @@ public function lowMemoryNotification() { } + /** + * Optional notification to tell V8 the current performance requirements + * of the embedder based on RAIL. + * V8 uses these notifications to guide heuristics. + * This is an unfinished experimental feature. Semantics and implementation + * may change frequently. + * + * @param int $rail_mode + * + * @return void + */ + public function setRAILMode(int $rail_mode) + { + } + /** * Check if V8 is dead and therefore unusable. This is the case after * fatal errors such as out-of-memory situations. diff --git a/stubs/src/KeyCollectionMode.php b/stubs/src/KeyCollectionMode.php index 6a7cbe9..0f12f3d 100644 --- a/stubs/src/KeyCollectionMode.php +++ b/stubs/src/KeyCollectionMode.php @@ -18,7 +18,7 @@ /** * Keys/Properties filter to limits the range of collected properties */ -class KeyCollectionMode +final class KeyCollectionMode { const kOwnOnly = 0; // limits the collected properties to the given Object only. kIncludesPrototypes const kIncludesPrototypes = 1; // will include all keys of the objects's prototype chain as well. diff --git a/stubs/src/PropertyAttribute.php b/stubs/src/PropertyAttribute.php index 3024e31..1cad345 100644 --- a/stubs/src/PropertyAttribute.php +++ b/stubs/src/PropertyAttribute.php @@ -16,7 +16,7 @@ namespace V8; -class PropertyAttribute +final class PropertyAttribute { const NONE = 0; const READ_ONLY = 1; diff --git a/stubs/src/PropertyFilter.php b/stubs/src/PropertyFilter.php index 82045da..4a6de41 100644 --- a/stubs/src/PropertyFilter.php +++ b/stubs/src/PropertyFilter.php @@ -18,7 +18,7 @@ /** * Property filter bits. They can be or'ed to build a composite filter. */ -class PropertyFilter +final class PropertyFilter { const ALL_PROPERTIES = 0; const ONLY_WRITABLE = 1; diff --git a/stubs/src/PropertyHandlerFlags.php b/stubs/src/PropertyHandlerFlags.php index eeb9451..bf16485 100644 --- a/stubs/src/PropertyHandlerFlags.php +++ b/stubs/src/PropertyHandlerFlags.php @@ -20,7 +20,7 @@ * Configuration flags for V8\NamedPropertyHandlerConfiguration or * V8\IndexedPropertyHandlerConfiguration. */ -class PropertyHandlerFlags +final class PropertyHandlerFlags { /** * None. diff --git a/stubs/src/RAILMode.php b/stubs/src/RAILMode.php new file mode 100644 index 0000000..05e457a --- /dev/null +++ b/stubs/src/RAILMode.php @@ -0,0 +1,44 @@ + + * + * Licensed under the MIT license: http://opensource.org/licenses/MIT + * + * For the full copyright and license information, please view the + * LICENSE file that was distributed with this source or visit + * http://opensource.org/licenses/MIT + */ + + +namespace V8; + + +/** + * Option flags passed to the SetRAILMode function. + * See documentation https://developers.google.com/web/tools/chrome-devtools/profile/evaluate-performance/rail + */ +final class RAILMode +{ + /** + * Response performance mode: In this mode very low virtual machine latency is provided. + * V8 will try to avoid JavaScript execution interruptions. Throughput may be throttled. + */ + const PERFORMANCE_RESPONSE = 0; + /** + * Animation performance mode: In this mode low virtual machine latency is provided. + * V8 will try to avoid as many JavaScript execution interruptions + * as possible. Throughput may be throttled. This is the default mode. + */ + const PERFORMANCE_ANIMATION = 1; + /** + * Idle performance mode: The embedder is idle. V8 can complete deferred work in this mode. + */ + const PERFORMANCE_IDLE = 2; + /** + * Load performance mode: In this mode high throughput is provided. V8 may turn off latency optimizations. + */ + const PERFORMANCE_LOAD = 3; +} diff --git a/tests/001-verify_extension_entities.phpt b/tests/001-verify_extension_entities.phpt index 5152f5c..d289f2d 100644 --- a/tests/001-verify_extension_entities.phpt +++ b/tests/001-verify_extension_entities.phpt @@ -260,6 +260,12 @@ final class V8\IndexFilter const INCLUDE_INDICES = 0 const SKIP_INDICES = 1 +final class V8\RAILMode + const PERFORMANCE_RESPONSE = 0 + const PERFORMANCE_ANIMATION = 1 + const PERFORMANCE_IDLE = 2 + const PERFORMANCE_LOAD = 3 + class V8\Exceptions\Exception extends Exception implements Throwable @@ -345,6 +351,7 @@ class V8\Isolate public function throwException(V8\Context $context, V8\Value $value, Throwable $e) public function idleNotificationDeadline($deadline_in_seconds): bool public function lowMemoryNotification() + public function setRAILMode(int $rail_mode) public function terminateExecution() public function isExecutionTerminating(): bool public function cancelTerminateExecution() diff --git a/tests/Isolate.phpt b/tests/Isolate.phpt index f7424bb..969420a 100644 --- a/tests/Isolate.phpt +++ b/tests/Isolate.phpt @@ -25,9 +25,41 @@ $helper->line(); $helper->method_export($isolate, 'getHeapStatistics'); $isolate->lowMemoryNotification(); + +$helper->line(); + +try { + $isolate->memoryPressureNotification(-2); +} catch (\V8\Exceptions\ValueException $e) { + $helper->exception_export($e); +} + $isolate->memoryPressureNotification(\V8\Isolate::MEMORY_PRESSURE_LEVEL_NONE); $isolate->memoryPressureNotification(\V8\Isolate::MEMORY_PRESSURE_LEVEL_MODERATE); $isolate->memoryPressureNotification(\V8\Isolate::MEMORY_PRESSURE_LEVEL_CRITICAL); +try { + $isolate->memoryPressureNotification(42); +} catch (\V8\Exceptions\ValueException $e) { + $helper->exception_export($e); +} + +$helper->line(); + +try { + $isolate->setRAILMode(-2); +} catch (\V8\Exceptions\ValueException $e) { + $helper->exception_export($e); +} +$isolate->setRAILMode(\V8\RAILMode::PERFORMANCE_RESPONSE); +$isolate->setRAILMode(\V8\RAILMode::PERFORMANCE_ANIMATION); +$isolate->setRAILMode(\V8\RAILMode::PERFORMANCE_IDLE); +$isolate->setRAILMode(\V8\RAILMode::PERFORMANCE_LOAD); +try { + $isolate->setRAILMode(42); +} catch (\V8\Exceptions\ValueException $e) { + $helper->exception_export($e); +} + $isolate = null; @@ -47,7 +79,7 @@ V8\Isolate::MEMORY_PRESSURE_LEVEL_MODERATE = 1 V8\Isolate::MEMORY_PRESSURE_LEVEL_CRITICAL = 2 V8\Isolate->getHeapStatistics(): - object(V8\HeapStatistics)#27 (9) { + object(V8\HeapStatistics)#28 (9) { ["total_heap_size":"V8\HeapStatistics":private]=> float(%f) ["total_heap_size_executable":"V8\HeapStatistics":private]=> @@ -67,3 +99,9 @@ V8\Isolate->getHeapStatistics(): ["does_zap_garbage":"V8\HeapStatistics":private]=> bool(false) } + +V8\Exceptions\ValueException: Invalid memory pressure level given. See V8\Isolate MEMORY_PRESSURE_LEVEL_* class constants for available levels. +V8\Exceptions\ValueException: Invalid memory pressure level given. See V8\Isolate MEMORY_PRESSURE_LEVEL_* class constants for available levels. + +V8\Exceptions\ValueException: Invalid RAIL mode given. See V8\RAILMode class constants for available values. +V8\Exceptions\ValueException: Invalid RAIL mode given. See V8\RAILMode class constants for available values.