MySQL 9.3.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
jit_executor::JavaScript Class Reference

MRS JavaScript Implementation. More...

#include <jit_executor_javascript.h>

Inheritance diagram for jit_executor::JavaScript:
[legend]

Classes

struct  Get_content_set_path
 
struct  Get_current_mrs_user_id
 
struct  Get_session
 
struct  Synch_error
 
struct  Synch_return
 

Public Member Functions

 ~JavaScript () override=default
 
bool start (size_t id, const std::shared_ptr< IFile_system > &fs={}, const Dictionary_t &predefined_globals={})
 
void stop ()
 
std::string execute (const std::string &code, int timeout, ResultType result_type, const GlobalCallbacks &callbacks)
 
std::string get_parameter_string (const std::vector< Value > &parameters) const
 
int64_t eval (poly_reference source, poly_value *result) const
 Wraps a call to poly_context_eval. More...
 
poly_value create_source (const std::string &source, const std::string &code_str) const
 Creates a Source object. More...
 
bool wait_for_idle ()
 
size_t id ()
 
- Public Member Functions inherited from shcore::polyglot::Java_script_interface
 ~Java_script_interface () override=default
 
const char * get_language_id () const override
 
void initialize (const std::shared_ptr< IFile_system > &fs={}) override
 
void finalize () override
 
poly_value undefined () const override
 Return the a guest language interpretation of the Undefined C++ value. More...
 
bool is_undefined (poly_value value) const override
 Returns true if the provided value is undefined in the guest language. More...
 
poly_value array_buffer (const std::string &data) const override
 Return the guest language interpretation of a binary string. More...
 
bool is_object (poly_value object, std::string *class_name=nullptr) const override
 Return true if the guest language identifies the value as an object. More...
 
const std::vector< std::string > & keywords () const override
 Retrieves the list of keywords in the guest language. More...
 
 Polyglot_language (Polyglot_common_context *common_context, const std::string &debug_port="")
 
 Polyglot_language (const Polyglot_language &)=delete
 
 Polyglot_language (Polyglot_language &&)=delete
 
- Public Member Functions inherited from shcore::polyglot::Polyglot_language
 Polyglot_language (Polyglot_common_context *common_context, const std::string &debug_port="")
 
 Polyglot_language (const Polyglot_language &)=delete
 
Polyglot_languageoperator= (const Polyglot_language &)=delete
 
 Polyglot_language (Polyglot_language &&)=delete
 
Polyglot_languageoperator= (Polyglot_language &&)=delete
 
virtual ~Polyglot_language ()=default
 
virtual void init_context_builder ()
 
Polyglot_languagelanguage ()
 The polyglot_utils file has the following functions that can be used to export C++ functions as polyglot global functions: More...
 
void throw_jit_executor_exception (const Jit_executor_exception &exception)
 Throws a specific exception type in the GraalVM environment, with a specific message. More...
 
virtual poly_value from_native_object (const Object_bridge_t &object) const =0
 Converts a C++ object into a representation of the object in the guest language. More...
 
void throw_exception_object (const shcore::Dictionary_t &data) const
 Translates a dictionary object into an exception in the guest language. More...
 
void throw_exception_object (const Polyglot_error &data) const
 Translates a Polyglot_error into an exception in the guest language. More...
 
int64_t eval (const std::string &source, const std::string &code_str, poly_value *result) const
 Wraps a call to poly_context_eval. More...
 
poly_value create_source (const std::string &path) const
 
std::pair< Value, bool > debug (const std::string &path)
 Debugs the given script. More...
 
std::pair< Value, bool > execute (const std::string &code_str, const std::string &source)
 Executes the given script. More...
 
virtual bool load_plugin (const std::string &path)
 This function should be implemented to provide plugin load support. More...
 
poly_context copy_global_context () const
 Creates a copy of the global context. More...
 
poly_value poly_string (const std::string &data) const
 
std::string to_string (poly_value obj) const
 
poly_context context () const
 
poly_thread thread () const
 
const std::shared_ptr< Polyglot_object > & globals () const
 
poly_reference store (poly_value value)
 
void erase (poly_reference value)
 
void set_global (const std::string &name, const Value &value) const
 
void set_global (const std::string &name, poly_value value) const
 
void set_global_function (const std::string &name, poly_callback callback, void *data=nullptr)
 
Store get_global (const std::string &name) const
 
void terminate ()
 
bool is_terminating () const
 
Script_scope enter_script (const std::string &s)
 
Value convert (poly_value value) const
 
poly_value convert (const Value &value) const
 
Argument_list convert_args (const std::vector< poly_value > &args) const
 
poly_value type_info (poly_value value) const
 
bool get_member (poly_value object, const char *name, poly_value *member) const
 
std::string current_script_folder () const
 
Polyglot_common_contextcommon_context ()
 

Private Member Functions

void run ()
 
void stop_run_thread ()
 
Value native_object (poly_value object)
 
Value native_array (poly_value object)
 
Value to_native_object (poly_value object, const std::string &class_name) override
 Converts a guest language object into its C++ representation. More...
 
void output_handler (const char *bytes, size_t length) override
 
void error_handler (const char *bytes, size_t length) override
 
poly_value from_native_object (const Object_bridge_t &object) const override
 
void create_result (const Value &result, ResultState state=ResultState::Ok)
 
void create_result (const shcore::polyglot::Polyglot_error &error)
 
poly_value synch_return (const std::vector< poly_value > &args)
 
poly_value synch_error (const std::vector< poly_value > &args)
 
void resolve_promise (poly_value promise)
 
shcore::Value get_session (const std::vector< shcore::Value > &args)
 
poly_value get_current_mrs_user_id ()
 
shcore::Value get_content_set_path (const std::vector< shcore::Value > &args)
 
void set_processing_state (ProcessingState state)
 

Private Attributes

std::unique_ptr< std::thread > m_execution_thread
 
Dictionary_t m_predefined_globals
 
mysql_harness::WaitingMPSCQueue< std::variant< std::monostate, Code > > m_code
 
mysql_harness::WaitingMPSCQueue< Resultm_result
 
ResultType m_result_type
 
poly_value m_promise_resolver
 
const GlobalCallbacksm_global_callbacks = nullptr
 
std::shared_ptr< shcore::polyglot::Sessionm_session
 
std::optional< ProcessingStatem_processing_state
 
std::condition_variable m_processing_state_condition
 
std::mutex m_processing_state_mutex
 
size_t m_id = 0
 

Additional Inherited Members

- Protected Member Functions inherited from shcore::polyglot::Polyglot_language
poly_value wrap_callback (poly_callback callback, void *data) const
 
void clear_is_terminating ()
 
- Protected Attributes inherited from shcore::polyglot::Polyglot_language
Polyglot_common_contextm_common_context
 
poly_thread m_thread = nullptr
 
poly_context_builder m_context_builder = nullptr
 
Store m_context
 
std::unique_ptr< Polyglot_type_bridgerm_types
 
std::shared_ptr< Polyglot_objectm_globals
 
Current_script m_current_script
 
std::unique_ptr< Polyglot_storagem_storage
 
std::shared_ptr< IFile_systemm_file_system
 
std::string m_debug_port
 

Detailed Description

MRS JavaScript Implementation.

Starts the JavaScript engine in a thread for execution of code from the MRS end points. A threaded version is needed to support the JavaScript Promise resolution to get the final result.

To achieve these two global functions are exposed: synch_return and synch_error, such function would be used on the promise resolution by executing: promise.then(value => synch_return(value), error=>synch_error(err0r))

Constructor & Destructor Documentation

◆ ~JavaScript()

jit_executor::JavaScript::~JavaScript ( )
overridedefault

Member Function Documentation

◆ create_result() [1/2]

void jit_executor::JavaScript::create_result ( const shcore::polyglot::Polyglot_error error)
private

◆ create_result() [2/2]

void jit_executor::JavaScript::create_result ( const Value result,
ResultState  state = ResultState::Ok 
)
private

◆ create_source()

poly_value jit_executor::JavaScript::create_source ( const std::string &  source,
const std::string &  code_str 
) const

Creates a Source object.

◆ error_handler()

void jit_executor::JavaScript::error_handler ( const char *  bytes,
size_t  length 
)
overrideprivatevirtual

◆ eval()

int64_t jit_executor::JavaScript::eval ( poly_reference  source,
poly_value *  result 
) const

Wraps a call to poly_context_eval.

◆ execute()

std::string jit_executor::JavaScript::execute ( const std::string &  code,
int  timeout,
ResultType  result_type,
const GlobalCallbacks callbacks 
)

◆ from_native_object()

poly_value jit_executor::JavaScript::from_native_object ( const Object_bridge_t &  object) const
overrideprivate

◆ get_content_set_path()

shcore::Value jit_executor::JavaScript::get_content_set_path ( const std::vector< shcore::Value > &  args)
private

◆ get_current_mrs_user_id()

poly_value jit_executor::JavaScript::get_current_mrs_user_id ( )
private

◆ get_parameter_string()

std::string jit_executor::JavaScript::get_parameter_string ( const std::vector< Value > &  parameters) const

◆ get_session()

shcore::Value jit_executor::JavaScript::get_session ( const std::vector< shcore::Value > &  args)
private

◆ id()

size_t jit_executor::JavaScript::id ( )
inline

◆ native_array()

Value jit_executor::JavaScript::native_array ( poly_value  object)
private

◆ native_object()

Value jit_executor::JavaScript::native_object ( poly_value  object)
private

◆ output_handler()

void jit_executor::JavaScript::output_handler ( const char *  bytes,
size_t  length 
)
overrideprivatevirtual

◆ resolve_promise()

void jit_executor::JavaScript::resolve_promise ( poly_value  promise)
private

◆ run()

void jit_executor::JavaScript::run ( )
private

◆ set_processing_state()

void jit_executor::JavaScript::set_processing_state ( ProcessingState  state)
private

◆ start()

bool jit_executor::JavaScript::start ( size_t  id,
const std::shared_ptr< IFile_system > &  fs = {},
const Dictionary_t predefined_globals = {} 
)

◆ stop()

void jit_executor::JavaScript::stop ( )

◆ stop_run_thread()

void jit_executor::JavaScript::stop_run_thread ( )
private

◆ synch_error()

poly_value jit_executor::JavaScript::synch_error ( const std::vector< poly_value > &  args)
private

◆ synch_return()

poly_value jit_executor::JavaScript::synch_return ( const std::vector< poly_value > &  args)
private

◆ to_native_object()

Value jit_executor::JavaScript::to_native_object ( poly_value  object,
const std::string &  class_name 
)
overrideprivatevirtual

Converts a guest language object into its C++ representation.

Reimplemented from shcore::polyglot::Polyglot_language.

◆ wait_for_idle()

bool jit_executor::JavaScript::wait_for_idle ( )

Member Data Documentation

◆ m_code

mysql_harness::WaitingMPSCQueue<std::variant<std::monostate, Code> > jit_executor::JavaScript::m_code
private

◆ m_execution_thread

std::unique_ptr<std::thread> jit_executor::JavaScript::m_execution_thread
private

◆ m_global_callbacks

const GlobalCallbacks* jit_executor::JavaScript::m_global_callbacks = nullptr
private

◆ m_id

size_t jit_executor::JavaScript::m_id = 0
private

◆ m_predefined_globals

Dictionary_t jit_executor::JavaScript::m_predefined_globals
private

◆ m_processing_state

std::optional<ProcessingState> jit_executor::JavaScript::m_processing_state
private

◆ m_processing_state_condition

std::condition_variable jit_executor::JavaScript::m_processing_state_condition
private

◆ m_processing_state_mutex

std::mutex jit_executor::JavaScript::m_processing_state_mutex
private

◆ m_promise_resolver

poly_value jit_executor::JavaScript::m_promise_resolver
private

◆ m_result

mysql_harness::WaitingMPSCQueue<Result> jit_executor::JavaScript::m_result
private

◆ m_result_type

ResultType jit_executor::JavaScript::m_result_type
private

◆ m_session

std::shared_ptr<shcore::polyglot::Session> jit_executor::JavaScript::m_session
private

The documentation for this class was generated from the following files: