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

Commit 3050443

Browse files
committed
Pass Isolate pointer to v8::String::Utf8Value constructors, closes #46
1 parent 9fd0cd8 commit 3050443

13 files changed

+31
-46
lines changed

scripts/test_v8/hello_world.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(int argc, char* argv[]) {
7878
Local<Value> result = script->Run();
7979

8080
// Convert the result to an UTF8 string and print it.
81-
String::Utf8Value utf8(result);
81+
String::Utf8Value utf8(isolate, result);
8282
printf("%s\n", *utf8);
8383
}
8484

src/php_v8_exceptions.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ void php_v8_create_try_catch_exception(zval *return_value, php_v8_isolate_t *php
5252
const char *message = NULL;
5353

5454
PHP_V8_DECLARE_LIMITS(php_v8_isolate);
55+
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
5556

5657
if ((try_catch == NULL) || (try_catch->Exception()->IsNull() && try_catch->Message().IsEmpty() && !try_catch->CanContinue() && try_catch->HasTerminated())) {
5758
if (limits->time_limit_hit) {
@@ -68,10 +69,9 @@ void php_v8_create_try_catch_exception(zval *return_value, php_v8_isolate_t *php
6869
object_init_ex(return_value, ce);
6970
zend_update_property_string(php_v8_try_catch_exception_class_entry, return_value, ZEND_STRL("message"), message);
7071
} else {
71-
v8::String::Utf8Value exception(try_catch->Exception());
72-
7372
ce = php_v8_try_catch_exception_class_entry;
74-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK_NODECL(exception, message);
73+
74+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING_NODECL(isolate, message, try_catch->Exception());
7575

7676
object_init_ex(return_value, ce);
7777
zend_update_property_string(php_v8_try_catch_exception_class_entry, return_value, ZEND_STRL("message"), message);

src/php_v8_message.cc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,18 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph
2929

3030
object_init_ex(return_value, this_ce);
3131

32-
v8::Isolate *isolate = php_v8_isolate->isolate;
32+
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
3333
v8::Local<v8::Context> context = isolate->GetEnteredContext();
3434

3535
/* v8::Message::Get */
3636
if (!message->Get().IsEmpty()) {
37-
v8::String::Utf8Value message_utf8(message->Get());
38-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(message_utf8, message_chars);
37+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, message_chars, message->Get());
3938
zend_update_property_string(this_ce, return_value, ZEND_STRL("message"), message_chars);
4039
}
4140

4241
/* v8::Message::GetSourceLine */
4342
if (!message->GetSourceLine(context).IsEmpty()) {
44-
v8::String::Utf8Value source_line_utf8(message->GetSourceLine(context).ToLocalChecked());
45-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(source_line_utf8, source_line_chars);
43+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, source_line_chars, message->GetSourceLine(context).ToLocalChecked());
4644
zend_update_property_string(this_ce, return_value, ZEND_STRL("source_line"), source_line_chars);
4745
}
4846

@@ -54,8 +52,7 @@ void php_v8_message_create_from_message(zval *return_value, php_v8_isolate_t *ph
5452

5553
/* v8::Message::GetScriptResourceName */
5654
if (!message->GetScriptResourceName().IsEmpty() && !message->GetScriptResourceName()->IsUndefined()) {
57-
v8::String::Utf8Value script_resource_name_utf8(message->GetScriptResourceName());
58-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(script_resource_name_utf8, script_resource_name_chars);
55+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, script_resource_name_chars, message->GetScriptResourceName());
5956
zend_update_property_string(this_ce, return_value, ZEND_STRL("resource_name"), script_resource_name_chars);
6057
}
6158

src/php_v8_object.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static PHP_METHOD(Object, setAccessor) {
447447
v8::Local<v8::Object> local_object = php_v8_value_get_local_as<v8::Object>(php_v8_value);
448448
v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);
449449

450-
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
450+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);
451451

452452
attributes = attributes ? attributes & PHP_V8_PROPERTY_ATTRIBUTE_FLAGS : attributes;
453453
settings = settings ? settings & PHP_V8_ACCESS_CONTROL_FLAGS : settings;
@@ -574,7 +574,7 @@ static PHP_METHOD(Object, setNativeDataProperty) {
574574
v8::Local<v8::Object> local_object = php_v8_value_get_local_as<v8::Object>(php_v8_value);
575575
v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);
576576

577-
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
577+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);
578578

579579
attributes = attributes ? attributes & PHP_V8_PROPERTY_ATTRIBUTE_FLAGS : attributes;
580580

src/php_v8_object_template.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static PHP_METHOD(ObjectTemplate, setAccessor) {
245245

246246
v8::Local<v8::Name> local_name = php_v8_value_get_local_as<v8::Name>(php_v8_name);
247247

248-
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(name, local_name);
248+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, name, local_name);
249249

250250
v8::AccessorNameGetterCallback getter;
251251
v8::AccessorNameSetterCallback setter = 0;

src/php_v8_script_origin.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ extern void php_v8_create_script_origin(zval *return_value, v8::Local<v8::Contex
2727
zval options_zv;
2828

2929
object_init_ex(return_value, this_ce);
30+
v8::Isolate *isolate= context->GetIsolate();
3031

3132
/* v8::ScriptOrigin::ResourceName */
3233
if (!origin.ResourceName().IsEmpty() && !origin.ResourceName()->IsUndefined()) {
33-
v8::String::Utf8Value resource_name_utf8(origin.ResourceName());
34-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(resource_name_utf8, resource_name_chars);
34+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, resource_name_chars, origin.ResourceName());
3535
zend_update_property_string(this_ce, return_value, ZEND_STRL("resource_name"), resource_name_chars);
3636
}
3737

@@ -57,8 +57,7 @@ extern void php_v8_create_script_origin(zval *return_value, v8::Local<v8::Contex
5757

5858
/* v8::SourceMapUrl::ResourceName */
5959
if (!origin.SourceMapUrl().IsEmpty() && !origin.SourceMapUrl()->IsUndefined()) {
60-
v8::String::Utf8Value source_map_url_utf8(origin.SourceMapUrl());
61-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(source_map_url_utf8, source_map_url_chars);
60+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, source_map_url_chars, origin.SourceMapUrl());
6261
zend_update_property_string(this_ce, return_value, ZEND_STRL("source_map_url"), source_map_url_chars);
6362
}
6463
}

src/php_v8_stack_frame.cc

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ zend_class_entry *php_v8_stack_frame_class_entry;
2222
#define this_ce php_v8_stack_frame_class_entry
2323

2424

25-
void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local<v8::StackFrame> frame) {
25+
void php_v8_stack_frame_create_from_stack_frame(v8::Isolate *isolate, zval *return_value, v8::Local<v8::StackFrame> frame) {
2626

2727
assert(!frame.IsEmpty());
2828

@@ -41,23 +41,19 @@ void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local<v8
4141

4242
/* v8::StackFrame::GetScriptName */
4343
if (!frame->GetScriptName().IsEmpty()) {
44-
v8::String::Utf8Value script_name_utf8(frame->GetScriptName());
45-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(script_name_utf8, script_name_chars);
44+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, script_name_chars, frame->GetScriptName());
4645
zend_update_property_string(this_ce, return_value, ZEND_STRL("script_name"), script_name_chars);
4746
}
4847

4948
/* v8::StackFrame::GetScriptNameOrSourceURL */
5049
if (!frame->GetScriptNameOrSourceURL().IsEmpty()) {
51-
v8::String::Utf8Value script_name_or_source_url_utf8(frame->GetScriptNameOrSourceURL());
52-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(script_name_or_source_url_utf8, script_name_or_source_url_chars);
53-
zend_update_property_string(this_ce, return_value, ZEND_STRL("script_name_or_source_url"),
54-
script_name_or_source_url_chars);
50+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, script_name_or_source_url_chars, frame->GetScriptNameOrSourceURL());
51+
zend_update_property_string(this_ce, return_value, ZEND_STRL("script_name_or_source_url"), script_name_or_source_url_chars);
5552
}
5653

5754
/* v8::StackFrame::GetFunctionName */
5855
if (!frame->GetFunctionName().IsEmpty()) {
59-
v8::String::Utf8Value function_name_utf8(frame->GetFunctionName());
60-
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(function_name_utf8, function_name_chars);
56+
PHP_V8_CONVERT_FROM_V8_STRING_TO_STRING(isolate, function_name_chars, frame->GetFunctionName());
6157
zend_update_property_string(this_ce, return_value, ZEND_STRL("function_name"), function_name_chars);
6258
}
6359

src/php_v8_stack_frame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extern "C" {
2525

2626
extern zend_class_entry* php_v8_stack_frame_class_entry;
2727

28-
extern void php_v8_stack_frame_create_from_stack_frame(zval *return_value, v8::Local<v8::StackFrame> frame);
28+
extern void php_v8_stack_frame_create_from_stack_frame(v8::Isolate *isolate, zval *return_value, v8::Local<v8::StackFrame> frame);
2929

3030

3131
PHP_MINIT_FUNCTION(php_v8_stack_frame);

src/php_v8_stack_trace.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void php_v8_stack_trace_create_from_stack_trace(zval *return_value, php_v8_isola
2929

3030
object_init_ex(return_value, this_ce);
3131

32-
v8::Isolate *isolate = php_v8_isolate->isolate;
32+
PHP_V8_DECLARE_ISOLATE(php_v8_isolate);
3333

3434
/* v8::StackTrace::GetFrames */
3535
/* v8::StackTrace::GetFrame */
@@ -42,7 +42,7 @@ void php_v8_stack_trace_create_from_stack_trace(zval *return_value, php_v8_isola
4242
zval frame_zv;
4343

4444
for (uint32_t i = 0; i < frames_cnt; i++) {
45-
php_v8_stack_frame_create_from_stack_frame(&frame_zv, trace->GetFrame(i));
45+
php_v8_stack_frame_create_from_stack_frame(isolate, &frame_zv, trace->GetFrame(i));
4646
add_index_zval(&frames_array_zv, i, &frame_zv);
4747
}
4848

src/php_v8_string.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static PHP_METHOD(String, value)
5959

6060
v8::Local<v8::Value> str_tpl = php_v8_value_get_local(php_v8_value);
6161

62-
v8::String::Utf8Value str(str_tpl);
62+
v8::String::Utf8Value str(isolate, str_tpl);
6363

6464
PHP_V8_CONVERT_UTF8VALUE_TO_STRING_WITH_CHECK(str, cstr);
6565

0 commit comments

Comments
 (0)