From a493919a17633f82c6121ccc2890b65d854341ac Mon Sep 17 00:00:00 2001 From: Stefan Siegl Date: Fri, 10 Mar 2017 22:58:53 +0100 Subject: [PATCH] extract function zend_long_to_v8js --- php_v8js_macros.h | 7 +++++-- v8js_convert.cc | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/php_v8js_macros.h b/php_v8js_macros.h index d2f32d9..f781fb5 100644 --- a/php_v8js_macros.h +++ b/php_v8js_macros.h @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2016 The PHP Group | + | Copyright (c) 1997-2017 The PHP Group | +----------------------------------------------------------------------+ | http://www.opensource.org/licenses/mit-license.php MIT License | +----------------------------------------------------------------------+ @@ -79,7 +79,10 @@ extern "C" { /* Convert zval into V8 value */ -v8::Handle zval_to_v8js(zval *, v8::Isolate * TSRMLS_DC); +v8::Handle zval_to_v8js(zval *, v8::Isolate *); + +/* Convert zend_long into V8 value */ +v8::Handle zend_long_to_v8js(zend_long, v8::Isolate *); /* Convert V8 value into zval */ int v8js_to_zval(v8::Handle, zval *, int, v8::Isolate * TSRMLS_DC); diff --git a/v8js_convert.cc b/v8js_convert.cc index 02c862a..ca04478 100644 --- a/v8js_convert.cc +++ b/v8js_convert.cc @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2016 The PHP Group | + | Copyright (c) 1997-2017 The PHP Group | +----------------------------------------------------------------------+ | http://www.opensource.org/licenses/mit-license.php MIT License | +----------------------------------------------------------------------+ @@ -100,10 +100,19 @@ static v8::Handle v8js_hash_to_jsarr(zval *value, v8::Isolate *isolat } /* }}} */ -v8::Handle zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC) /* {{{ */ +v8::Handle zend_long_to_v8js(zend_long v, v8::Isolate *isolate) /* {{{ */ +{ + if (v < - std::numeric_limits::min() || v > std::numeric_limits::max()) { + return V8JS_FLOAT(static_cast(v)); + } else { + return V8JS_INT(static_cast(v)); + } +} +/* }}} */ + +v8::Handle zval_to_v8js(zval *value, v8::Isolate *isolate) /* {{{ */ { v8::Handle jsValue; - zend_long v; zend_string *value_str; zend_class_entry *ce; @@ -147,12 +156,7 @@ v8::Handle zval_to_v8js(zval *value, v8::Isolate *isolate TSRMLS_DC) break; case IS_LONG: - v = Z_LVAL_P(value); - if (v < - std::numeric_limits::min() || v > std::numeric_limits::max()) { - jsValue = V8JS_FLOAT(static_cast(v)); - } else { - jsValue = V8JS_INT(static_cast(v)); - } + jsValue = zend_long_to_v8js(Z_LVAL_P(value), isolate); break; case IS_DOUBLE: