1
1
/*
2
- * Copyright (c) 2024, Oracle and/or its affiliates.
2
+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3
3
*
4
4
* This program is free software; you can redistribute it and/or modify
5
5
* it under the terms of the GNU General Public License, version 2.0,
25
25
26
26
#include " mysqlshdk/scripting/polyglot/languages/polyglot_common_context.h"
27
27
28
+ #include " mysqlshdk/libs/utils/utils_general.h"
28
29
#include " mysqlshdk/libs/utils/utils_string.h"
29
30
#include " mysqlshdk/scripting/polyglot/native_wrappers/polyglot_collectable.h"
30
31
#include " mysqlshdk/scripting/polyglot/utils/polyglot_error.h"
34
35
namespace shcore {
35
36
namespace polyglot {
36
37
37
- void Polyglot_common_context::initialize () {
38
- if (const auto rc = poly_create_isolate (NULL , &m_isolate, &m_thread);
39
- poly_ok != rc) {
40
- throw Polyglot_generic_error (
41
- shcore::str_format (" Error creating polyglot isolate: %d" , rc));
38
+ void Polyglot_common_context::initialize (
39
+ const std::vector<std::string> &isolate_args) {
40
+ if (!isolate_args.empty ()) {
41
+ std::vector<char *> raw_isolate_args = {nullptr };
42
+ for (const auto &arg : isolate_args) {
43
+ raw_isolate_args.push_back (const_cast <char *>(arg.data ()));
44
+ }
45
+
46
+ auto params = raw_isolate_args.data ();
47
+ poly_isolate_params isolate_params;
48
+ if (poly_ok != poly_set_isolate_params (&isolate_params,
49
+ isolate_args.size () + 1 , params)) {
50
+ throw Polyglot_generic_error (" Error creating polyglot isolate params" );
51
+ }
52
+
53
+ if (const auto rc =
54
+ poly_create_isolate (&isolate_params, &m_isolate, &m_thread);
55
+ rc != poly_ok) {
56
+ throw Polyglot_generic_error (
57
+ shcore::str_format (" Error creating polyglot isolate: %d" , rc));
58
+ }
59
+ } else {
60
+ if (const auto rc = poly_create_isolate (NULL , &m_isolate, &m_thread);
61
+ rc != poly_ok) {
62
+ throw Polyglot_generic_error (
63
+ shcore::str_format (" Error creating polyglot isolate: %d" , rc));
64
+ }
42
65
}
43
66
44
- m_garbage_collector.start (gc_config (), m_isolate);
45
-
46
67
m_scope = std::make_unique<Polyglot_scope>(m_thread);
47
68
48
69
if (const auto rc = poly_register_log_handler_callbacks (
@@ -64,11 +85,13 @@ void Polyglot_common_context::finalize() {
64
85
65
86
m_scope.reset ();
66
87
67
- m_garbage_collector.stop ();
68
-
69
- if (const auto rc = poly_tear_down_isolate (m_thread); rc != poly_ok) {
70
- std::string error{" polyglot error while tearing down the isolate" };
71
- log (error.data (), error.size ());
88
+ if (m_isolate && m_thread) {
89
+ if (const auto rc = poly_detach_all_threads_and_tear_down_isolate (m_thread);
90
+ rc != poly_ok) {
91
+ const auto error = shcore::str_format (
92
+ " Polyglot error while tearing down the isolate: %d" , rc);
93
+ log (error.data (), error.size ());
94
+ }
72
95
}
73
96
74
97
clean_collectables ();
0 commit comments