@@ -110,6 +110,7 @@ v8::Local<v8::Value> zend_long_to_v8js(zend_long v, v8::Isolate *isolate) /* {{{
110
110
111
111
v8::Local<v8::Value> zval_to_v8js (zval *value, v8::Isolate *isolate) /* {{{ */
112
112
{
113
+ v8js_ctx *ctx = (v8js_ctx *) isolate->GetData (0 );
113
114
v8::Local<v8::Value> jsValue;
114
115
zend_string *value_str;
115
116
zend_class_entry *ce;
@@ -150,19 +151,21 @@ v8::Local<v8::Value> zval_to_v8js(zval *value, v8::Isolate *isolate) /* {{{ */
150
151
break ;
151
152
}
152
153
153
- zval fname, retval;
154
- zval params[ 2 ] ;
155
- ZVAL_STRING (&fname, " mb_check_encoding " ) ;
156
- ZVAL_COPY_VALUE (¶ms[ 0 ], value );
157
- ZVAL_STRING (¶ms[1 ], " UTF-8 " );
158
-
159
- if ((SUCCESS == call_user_function (CG (function_table), NULL , &fname,
160
- &retval, 2 , params)) && (Z_TYPE (retval) == IS_TRUE )) {
161
- jsValue = V8JS_ZSTR (value_str);
162
- }
163
- else {
164
- jsValue = v8::String::NewFromOneByte (isolate, ( unsigned char *) ZSTR_VAL (value_str), v8::NewStringType:: kNormal , ZSTR_LEN (value_str)). ToLocalChecked ();
154
+ if (ctx-> flags & V8JS_FLAG_CHECK_BINARY_STRING) {
155
+ zval fname, retval ;
156
+ zval params[ 2 ] ;
157
+ ZVAL_STRING (&fname, " mb_check_encoding " );
158
+ ZVAL_COPY_VALUE (¶ms[0 ], value );
159
+ ZVAL_STRING (¶ms[ 1 ], " UTF-8 " );
160
+ if ((SUCCESS == call_user_function (CG (function_table), NULL , &fname,
161
+ &retval, 2 , params)) && (Z_TYPE (retval) == IS_FALSE )) {
162
+
163
+ jsValue = v8::String::NewFromOneByte (isolate, ( unsigned char *) ZSTR_VAL (value_str), v8::NewStringType:: kNormal , ZSTR_LEN (value_str)). ToLocalChecked ();
164
+ return jsValue;
165
+ }
165
166
}
167
+
168
+ jsValue = V8JS_ZSTR (value_str);
166
169
167
170
break ;
168
171
@@ -204,19 +207,19 @@ int v8js_to_zval(v8::Local<v8::Value> jsValue, zval *return_value, int flags, v8
204
207
205
208
if (jsValue->IsString ())
206
209
{
207
- v8::Local<v8::String> strOneByte = jsValue->ToString (v8_context).ToLocalChecked ();
208
- if (strOneByte->IsOneByte () && strOneByte->ContainsOnlyOneByte ()) {
209
- int length = strOneByte->Length ();
210
- char * char_value = new char [length + 1 ];
211
- strOneByte->WriteOneByte (isolate, reinterpret_cast <uint8_t *>(&char_value[0 ]), 0 , length);
212
-
213
- RETVAL_STRINGL (char_value, length);
214
- }
215
- else {
216
- v8::String::Utf8Value str (isolate, jsValue);
217
- const char *cstr = ToCString (str);
218
- RETVAL_STRINGL (cstr, str.length ());
210
+ if (ctx->flags & V8JS_FLAG_CHECK_BINARY_STRING) {
211
+ v8::Local<v8::String> strOneByte = jsValue->ToString (v8_context).ToLocalChecked ();
212
+ if (strOneByte->ContainsOnlyOneByte ()) {
213
+ int length = strOneByte->Length ();
214
+ char * char_value = new char [length + 1 ];
215
+ strOneByte->WriteOneByte (isolate, reinterpret_cast <uint8_t *>(&char_value[0 ]), 0 , length);
216
+ RETVAL_STRINGL (char_value, length);
217
+ return SUCCESS;
218
+ }
219
219
}
220
+ v8::String::Utf8Value str (isolate, jsValue);
221
+ const char *cstr = ToCString (str);
222
+ RETVAL_STRINGL (cstr, str.length ());
220
223
}
221
224
else if (jsValue->IsBoolean ())
222
225
{
0 commit comments