|
| 1 | +/* |
| 2 | + * This file is part of the pinepain/php-v8 PHP extension. |
| 3 | + * |
| 4 | + * Copyright (c) 2015-2017 Bogdan Padalko <pinepain@gmail.com> |
| 5 | + * |
| 6 | + * Licensed under the MIT license: http://opensource.org/licenses/MIT |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the |
| 9 | + * LICENSE file that was distributed with this source or visit |
| 10 | + * http://opensource.org/licenses/MIT |
| 11 | + */ |
| 12 | + |
| 13 | +#ifdef HAVE_CONFIG_H |
| 14 | +#include "config.h" |
| 15 | +#endif |
| 16 | + |
| 17 | +#include "php_v8_source.h" |
| 18 | +#include "php_v8_cached_data.h" |
| 19 | +#include "php_v8_string.h" |
| 20 | +#include "php_v8.h" |
| 21 | + |
| 22 | +zend_class_entry* php_v8_source_class_entry; |
| 23 | +#define this_ce php_v8_source_class_entry |
| 24 | + |
| 25 | +void php_v8_update_source_cached_data(zval *src_zv, v8::ScriptCompiler::Source *source) { |
| 26 | + if (!source->GetCachedData()) { |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + zval tmp; |
| 31 | + zval rv; |
| 32 | + |
| 33 | + zval *cached_data_zv = zend_read_property(this_ce, src_zv, ZEND_STRL("cached_data"), 0, &rv); |
| 34 | + |
| 35 | + if (!ZVAL_IS_NULL(cached_data_zv)) { |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + php_v8_create_cached_data(&tmp, source->GetCachedData()); |
| 40 | + |
| 41 | + zend_update_property(this_ce, src_zv, ZEND_STRL("cached_data"), &tmp); |
| 42 | +} |
| 43 | + |
| 44 | +static PHP_METHOD(V8Source, __construct) |
| 45 | +{ |
| 46 | + zval *source_string_zv = NULL; |
| 47 | + zval *origin_zv = NULL; |
| 48 | + zval *cached_data_zv = NULL; |
| 49 | + |
| 50 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|o!o!", &source_string_zv, &origin_zv, &cached_data_zv) == FAILURE) { |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + PHP_V8_VALUE_FETCH_WITH_CHECK(source_string_zv, php_v8_string); |
| 55 | + |
| 56 | + zend_update_property(this_ce, getThis(), ZEND_STRL("source_string"), source_string_zv); |
| 57 | + |
| 58 | + if (origin_zv != NULL) { |
| 59 | + zend_update_property(this_ce, getThis(), ZEND_STRL("origin"), origin_zv); |
| 60 | + } |
| 61 | + |
| 62 | + if (cached_data_zv != NULL) { |
| 63 | + zend_update_property(this_ce, getThis(), ZEND_STRL("cached_data"), cached_data_zv); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +static PHP_METHOD(V8Source, GetSourceString) |
| 68 | +{ |
| 69 | + zval rv; |
| 70 | + |
| 71 | + if (zend_parse_parameters_none() == FAILURE) { |
| 72 | + return; |
| 73 | + } |
| 74 | + |
| 75 | + RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("source_string"), 0, &rv), 1, 0); |
| 76 | +} |
| 77 | + |
| 78 | +static PHP_METHOD(V8Source, GetScriptOrigin) |
| 79 | +{ |
| 80 | + zval rv; |
| 81 | + |
| 82 | + if (zend_parse_parameters_none() == FAILURE) { |
| 83 | + return; |
| 84 | + } |
| 85 | + |
| 86 | + RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("origin"), 0, &rv), 1, 0); |
| 87 | +} |
| 88 | + |
| 89 | +static PHP_METHOD(V8Source, GetCachedData) |
| 90 | +{ |
| 91 | + zval rv; |
| 92 | + |
| 93 | + if (zend_parse_parameters_none() == FAILURE) { |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + RETVAL_ZVAL(zend_read_property(this_ce, getThis(), ZEND_STRL("cached_data"), 0, &rv), 1, 0); |
| 98 | +} |
| 99 | + |
| 100 | + |
| 101 | +ZEND_BEGIN_ARG_INFO_EX(arginfo_v8_source___construct, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 1) |
| 102 | + ZEND_ARG_OBJ_INFO(0, source_string, V8\\StringValue, 0) |
| 103 | + ZEND_ARG_OBJ_INFO(0, origin, V8\\ScriptOrigin, 1) |
| 104 | + ZEND_ARG_OBJ_INFO(0, cached_data, V8\\ScriptCompiler\\CachedData, 1) |
| 105 | +ZEND_END_ARG_INFO() |
| 106 | + |
| 107 | +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_source_GetSourceString, ZEND_RETURN_VALUE, 0, V8\\StringValue, 0) |
| 108 | +ZEND_END_ARG_INFO() |
| 109 | + |
| 110 | +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_source_GetScriptOrigin, ZEND_RETURN_VALUE, 0, V8\\ScriptOrigin, 1) |
| 111 | +ZEND_END_ARG_INFO() |
| 112 | + |
| 113 | +PHP_V8_ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_v8_source_GetCachedData, ZEND_RETURN_VALUE, 0, V8\\ScriptCompiler\\CachedData, 1) |
| 114 | +ZEND_END_ARG_INFO() |
| 115 | + |
| 116 | + |
| 117 | +static const zend_function_entry php_v8_source_methods[] = { |
| 118 | + PHP_ME(V8Source, __construct, arginfo_v8_source___construct, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR) |
| 119 | + PHP_ME(V8Source, GetSourceString, arginfo_v8_source_GetSourceString, ZEND_ACC_PUBLIC) |
| 120 | + PHP_ME(V8Source, GetScriptOrigin, arginfo_v8_source_GetScriptOrigin, ZEND_ACC_PUBLIC) |
| 121 | + PHP_ME(V8Source, GetCachedData, arginfo_v8_source_GetCachedData, ZEND_ACC_PUBLIC) |
| 122 | + |
| 123 | + PHP_FE_END |
| 124 | +}; |
| 125 | + |
| 126 | + |
| 127 | +PHP_MINIT_FUNCTION(php_v8_source) |
| 128 | +{ |
| 129 | + zend_class_entry ce; |
| 130 | + |
| 131 | + INIT_NS_CLASS_ENTRY(ce, "V8\\ScriptCompiler", "Source", php_v8_source_methods); |
| 132 | + this_ce = zend_register_internal_class(&ce); |
| 133 | + |
| 134 | + zend_declare_property_null(this_ce, ZEND_STRL("source_string"), ZEND_ACC_PRIVATE); |
| 135 | + zend_declare_property_null(this_ce, ZEND_STRL("origin"), ZEND_ACC_PRIVATE); |
| 136 | + zend_declare_property_null(this_ce, ZEND_STRL("cached_data"), ZEND_ACC_PRIVATE); |
| 137 | + |
| 138 | + return SUCCESS; |
| 139 | +} |
0 commit comments