Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js): replace deno_core with rquickjs #1713

Merged
merged 15 commits into from
May 4, 2024

Conversation

mayant15
Copy link
Contributor

@mayant15 mayant15 commented Apr 12, 2024

Summary:
Replaces V8 with QuickJS as the JS runtime

Issue Reference(s):
Fixes #1690
/claim 1690

Build & Testing:

  • I ran cargo test successfully.
  • I have run ./lint.sh --mode=fix to fix all linting issues raised by ./lint.sh --mode=check.

Checklist:

  • I have added relevant unit & integration tests.
  • I have updated the documentation accordingly.
  • I have performed a self-review of my code.
  • PR follows the naming convention of <type>(<optional scope>): <title>

Size Comparison

image

After

cargo bloat --crates --release -n 0

    Finished release [optimized] target(s) in 0.40s
    Analyzing target/release/tailcall

 File  .text     Size Crate
13.4%  21.0%   2.4MiB std
 6.6%  10.4%   1.2MiB tailcall
 3.4%   5.3% 612.6KiB [Unknown]
 2.7%   4.2% 482.8KiB hyper
 2.6%   4.1% 474.3KiB rustls
 2.4%   3.8% 442.2KiB h2
 2.4%   3.7% 428.0KiB async_graphql
 2.3%   3.6% 417.2KiB protobuf
 2.0%   3.1% 357.7KiB prost_reflect
 1.7%   2.6% 304.9KiB regex_automata
 1.6%   2.5% 285.0KiB tokio
 1.3%   2.1% 242.9KiB hashbrown
 1.3%   2.1% 240.1KiB regex_syntax
 1.2%   1.9% 216.1KiB serde_yaml
 1.2%   1.8% 209.7KiB opentelemetry_sdk
 1.0%   1.6% 183.9KiB serde_json
 1.0%   1.5% 176.4KiB clap_builder
 0.7%   1.1% 128.8KiB protox_parse
 0.7%   1.1% 124.2KiB http
 0.7%   1.1% 124.1KiB ring
 0.6%   1.0% 110.6KiB aho_corasick
 0.6%   0.9% 108.0KiB pest
 0.5%   0.9%  98.4KiB serde
 0.5%   0.7%  85.4KiB opentelemetry_stdout
 0.4%   0.7%  81.2KiB rquickjs_sys
 0.4%   0.7%  80.4KiB unsafe_libyaml
 0.4%   0.6%  74.5KiB moka
 0.4%   0.6%  73.2KiB reqwest
 0.4%   0.6%  72.9KiB tonic
 0.4%   0.6%  70.3KiB async_graphql_extension_apollo_tracing
 0.3%   0.5%  63.2KiB async_graphql_parser
 0.3%   0.5%  62.5KiB tracing_subscriber
 0.3%   0.5%  60.4KiB prost
 0.3%   0.5%  57.3KiB jsonwebtoken
 0.3%   0.5%  55.1KiB futures_util
 0.3%   0.5%  53.1KiB http_cache
 0.3%   0.4%  51.8KiB phonenumber
 0.3%   0.4%  50.5KiB opentelemetry
 0.3%   0.4%  50.5KiB serde_value
 0.3%   0.4%  49.6KiB nvml_wrapper_sys
 0.3%   0.4%  49.5KiB opentelemetry_proto
 0.3%   0.4%  48.5KiB url
 0.3%   0.4%  48.3KiB prometheus
 0.2%   0.4%  44.7KiB webpki
 0.2%   0.4%  40.8KiB async_graphql_value
 0.2%   0.3%  39.3KiB opentelemetry_otlp
 0.2%   0.3%  31.8KiB encoding_rs
 0.2%   0.3%  30.0KiB serde_path_to_error
 0.2%   0.2%  28.9KiB indexmap
 0.2%   0.2%  28.4KiB http_cache_semantics
 0.1%   0.2%  27.3KiB opentelemetry_prometheus
 0.1%   0.2%  26.5KiB inquire
 0.1%   0.2%  26.1KiB anyhow
 0.1%   0.2%  23.1KiB libmimalloc_sys
 0.1%   0.2%  22.4KiB sysinfo
 0.1%   0.2%  21.9KiB rquickjs_core
 0.1%   0.2%  21.5KiB prost_types
 0.1%   0.2%  20.9KiB chrono
 0.1%   0.2%  20.6KiB serde_qs
 0.1%   0.2%  17.5KiB crossterm
 0.1%   0.1%  16.1KiB libflate
 0.1%   0.1%  16.0KiB tower
 0.1%   0.1%  15.8KiB tokio_rustls
 0.1%   0.1%  15.2KiB idna
 0.1%   0.1%  14.9KiB rayon_core
 0.1%   0.1%  14.7KiB tracing_opentelemetry
 0.1%   0.1%  14.5KiB tracing_core
 0.1%   0.1%  13.8KiB http_cache_reqwest
 0.1%   0.1%  13.5KiB parking_lot
 0.1%   0.1%  12.6KiB base64
 0.1%   0.1%  11.4KiB bytes
 0.1%   0.1%  11.0KiB unicode_segmentation
 0.1%   0.1%  10.7KiB time
 0.1%   0.1%   9.4KiB dotenvy
 0.1%   0.1%   9.3KiB once_cell
 0.1%   0.1%   9.1KiB convert_case
 0.0%   0.1%   8.8KiB futures_channel
 0.0%   0.1%   8.7KiB schemars
 0.0%   0.1%   8.6KiB memchr
 0.0%   0.1%   8.6KiB futures_task
 0.0%   0.1%   8.4KiB rustls_pemfile
 0.0%   0.1%   8.3KiB crossbeam_channel
 0.0%   0.1%   8.0KiB sharded_slab
 0.0%   0.1%   7.3KiB rustls_pki_types
 0.0%   0.1%   7.1KiB futures_timer
 0.0%   0.1%   6.8KiB hyper_rustls
 0.0%   0.1%   6.0KiB futures_core
 0.0%   0.1%   5.9KiB http_serde
 0.0%   0.0%   5.8KiB regex
 0.0%   0.0%   5.7KiB htpasswd_verify
 0.0%   0.0%   5.5KiB ryu
 0.0%   0.0%   5.0KiB crossbeam_epoch
 0.0%   0.0%   4.9KiB ipnet
 0.0%   0.0%   4.9KiB opentelemetry_system_metrics
 0.0%   0.0%   4.8KiB opentelemetry_http
 0.0%   0.0%   4.7KiB httparse
 0.0%   0.0%   4.7KiB colored
 0.0%   0.0%   4.6KiB signal_hook
 0.0%   0.0%   4.4KiB unicode_normalization
 0.0%   0.0%   4.3KiB nom
 0.0%   0.0%   4.2KiB mime
 0.0%   0.0%   4.1KiB event_listener
 0.0%   0.0%   4.0KiB sha1
 0.0%   0.0%   3.9KiB regex_cache
 0.0%   0.0%   3.6KiB signal_hook_registry
 0.0%   0.0%   3.6KiB pwhash
 0.0%   0.0%   3.2KiB tracing
 0.0%   0.0%   3.1KiB nu_ansi_term
 0.0%   0.0%   3.1KiB bincode
 0.0%   0.0%   3.1KiB bcrypt
 0.0%   0.0%   3.0KiB webbrowser
 0.0%   0.0%   2.9KiB eyre
 0.0%   0.0%   2.7KiB libflate_lz77
 0.0%   0.0%   2.7KiB parking_lot_core
 0.0%   0.0%   2.5KiB md5
 0.0%   0.0%   2.5KiB mio
 0.0%   0.0%   2.4KiB anstream
 0.0%   0.0%   2.4KiB rustls_native_certs
 0.0%   0.0%   2.3KiB form_urlencoded
 0.0%   0.0%   2.3KiB blowfish
 0.0%   0.0%   2.1KiB anstyle
 0.0%   0.0%   1.9KiB reqwest_middleware
 0.0%   0.0%   1.9KiB protox
 0.0%   0.0%   1.9KiB hyper_timeout
 0.0%   0.0%   1.9KiB nvml_wrapper
 0.0%   0.0%   1.9KiB strsim
 0.0%   0.0%   1.9KiB crossbeam_deque
 0.0%   0.0%   1.8KiB thread_local
 0.0%   0.0%   1.8KiB cache_control
 0.0%   0.0%   1.8KiB percent_encoding
 0.0%   0.0%   1.8KiB sct
 0.0%   0.0%   1.7KiB security_framework
 0.0%   0.0%   1.7KiB tokio_util
 0.0%   0.0%   1.7KiB rayon
 0.0%   0.0%   1.6KiB smallvec
 0.0%   0.0%   1.6KiB tracing_log
 0.0%   0.0%   1.6KiB tokio_stream
 0.0%   0.0%   1.5KiB futures_executor
 0.0%   0.0%   1.5KiB httpdate
 0.0%   0.0%   1.5KiB opentelemetry_appender_tracing
 0.0%   0.0%   1.4KiB spin
 0.0%   0.0%   1.4KiB libloading
 0.0%   0.0%   1.4KiB triomphe
 0.0%   0.0%   1.3KiB async_lock
 0.0%   0.0%   1.2KiB event_listener_strategy
 0.0%   0.0%   1.2KiB crc32fast
 0.0%   0.0%   1.0KiB miette
 0.0%   0.0%   1.0KiB fast_chemail
 0.0%   0.0%     932B getrandom
 0.0%   0.0%     928B headers
 0.0%   0.0%     908B indenter
 0.0%   0.0%     856B core_foundation
 0.0%   0.0%     836B clap_lex
 0.0%   0.0%     788B uname
 0.0%   0.0%     652B tinyvec
 0.0%   0.0%     620B socket2
 0.0%   0.0%     620B serde_urlencoded
 0.0%   0.0%     600B linked_hash_map
 0.0%   0.0%     596B http_body
 0.0%   0.0%     548B quanta
 0.0%   0.0%     508B want
 0.0%   0.0%     408B rand
 0.0%   0.0%     396B parking
 0.0%   0.0%     332B slab
 0.0%   0.0%     324B ascii_utils
 0.0%   0.0%     268B headers_core
 0.0%   0.0%     260B zeroize
 0.0%   0.0%     248B tagptr
 0.0%   0.0%     184B log
 0.0%   0.0%     124B unicode_bidi
 0.0%   0.0%      96B untrusted
 0.0%   0.0%      20B subtle
 0.0%   0.0%       8B dyn_clone
63.7% 100.0%  11.3MiB .text section size, the file size is 17.8MiB

Note: numbers above are a result of guesswork. They are not 100% correct and never will be.

Before

cargo bloat --crates --release -n 0

    Finished release [optimized] target(s) in 0.24s
    Analyzing target/release/tailcall

 File  .text     Size Crate
27.6%  47.8%  14.4MiB v8
 8.5%  14.7%   4.4MiB [Unknown]
 4.8%   8.3%   2.5MiB std
 2.2%   3.9%   1.2MiB tailcall
 0.9%   1.6% 482.8KiB hyper
 0.9%   1.5% 474.3KiB rustls
 0.8%   1.5% 450.6KiB deno_core
 0.8%   1.4% 442.2KiB h2
 0.8%   1.4% 428.0KiB async_graphql
 0.8%   1.4% 417.2KiB protobuf
 0.7%   1.2% 357.3KiB prost_reflect
 0.6%   1.0% 304.9KiB regex_automata
 0.5%   0.9% 289.6KiB tokio
 0.5%   0.9% 275.3KiB hashbrown
 0.5%   0.8% 240.1KiB regex_syntax
 0.4%   0.7% 216.0KiB serde_yaml
 0.4%   0.7% 209.7KiB opentelemetry_sdk
 0.4%   0.6% 196.9KiB serde_json
 0.3%   0.6% 176.4KiB clap_builder
 0.2%   0.4% 128.8KiB protox_parse
 0.2%   0.4% 124.2KiB http
 0.2%   0.4% 124.1KiB ring
 0.2%   0.4% 116.8KiB serde
 0.2%   0.4% 110.6KiB aho_corasick
 0.2%   0.3% 106.1KiB pest
 0.2%   0.3%  85.4KiB opentelemetry_stdout
 0.2%   0.3%  80.4KiB unsafe_libyaml
 0.1%   0.2%  74.5KiB moka
 0.1%   0.2%  73.2KiB reqwest
 0.1%   0.2%  72.9KiB tonic
 0.1%   0.2%  70.3KiB async_graphql_extension_apollo_tracing
 0.1%   0.2%  64.9KiB async_graphql_parser
 0.1%   0.2%  62.4KiB tracing_subscriber
 0.1%   0.2%  60.4KiB prost
 0.1%   0.2%  57.3KiB jsonwebtoken
 0.1%   0.2%  55.3KiB futures_util
 0.1%   0.2%  53.1KiB http_cache
 0.1%   0.2%  51.8KiB phonenumber
 0.1%   0.2%  50.5KiB opentelemetry
 0.1%   0.2%  50.5KiB serde_value
 0.1%   0.2%  49.6KiB nvml_wrapper_sys
 0.1%   0.2%  49.5KiB opentelemetry_proto
 0.1%   0.2%  49.4KiB url
 0.1%   0.2%  48.3KiB prometheus
 0.1%   0.1%  44.7KiB webpki
 0.1%   0.1%  40.8KiB async_graphql_value
 0.1%   0.1%  39.3KiB opentelemetry_otlp
 0.1%   0.1%  34.6KiB anyhow
 0.1%   0.1%  31.8KiB encoding_rs
 0.1%   0.1%  30.0KiB serde_path_to_error
 0.1%   0.1%  28.4KiB http_cache_semantics
 0.1%   0.1%  27.3KiB opentelemetry_prometheus
 0.1%   0.1%  27.2KiB indexmap
 0.0%   0.1%  26.5KiB inquire
 0.0%   0.1%  23.1KiB sourcemap
 0.0%   0.1%  23.1KiB libmimalloc_sys
 0.0%   0.1%  22.4KiB sysinfo
 0.0%   0.1%  21.5KiB prost_types
 0.0%   0.1%  20.9KiB chrono
 0.0%   0.1%  20.6KiB serde_qs
 0.0%   0.1%  20.4KiB serde_v8
 0.0%   0.1%  17.5KiB crossterm
 0.0%   0.1%  16.1KiB libflate
 0.0%   0.1%  16.0KiB tower
 0.0%   0.1%  15.8KiB tokio_rustls
 0.0%   0.0%  15.2KiB idna
 0.0%   0.0%  14.9KiB rayon_core
 0.0%   0.0%  14.7KiB tracing_opentelemetry
 0.0%   0.0%  14.5KiB tracing_core
 0.0%   0.0%  13.8KiB http_cache_reqwest
 0.0%   0.0%  13.2KiB parking_lot
 0.0%   0.0%  12.6KiB base64
 0.0%   0.0%  11.4KiB bytes
 0.0%   0.0%  11.0KiB unicode_segmentation
 0.0%   0.0%  10.7KiB time
 0.0%   0.0%  10.7KiB futures_task
 0.0%   0.0%   9.6KiB once_cell
 0.0%   0.0%   9.5KiB futures_channel
 0.0%   0.0%   9.4KiB dotenvy
 0.0%   0.0%   9.1KiB convert_case
 0.0%   0.0%   8.7KiB schemars
 0.0%   0.0%   8.6KiB memchr
 0.0%   0.0%   8.4KiB rustls_pemfile
 0.0%   0.0%   8.3KiB crossbeam_channel
 0.0%   0.0%   8.0KiB sharded_slab
 0.0%   0.0%   7.3KiB rustls_pki_types
 0.0%   0.0%   7.1KiB futures_timer
 0.0%   0.0%   6.8KiB hyper_rustls
 0.0%   0.0%   6.0KiB futures_core
 0.0%   0.0%   5.9KiB http_serde
 0.0%   0.0%   5.8KiB regex
 0.0%   0.0%   5.7KiB htpasswd_verify
 0.0%   0.0%   5.5KiB ryu
 0.0%   0.0%   5.0KiB crossbeam_epoch
 0.0%   0.0%   4.9KiB ipnet
 0.0%   0.0%   4.9KiB opentelemetry_system_metrics
 0.0%   0.0%   4.8KiB opentelemetry_http
 0.0%   0.0%   4.7KiB httparse
 0.0%   0.0%   4.7KiB colored
 0.0%   0.0%   4.6KiB signal_hook
 0.0%   0.0%   4.4KiB unicode_normalization
 0.0%   0.0%   4.3KiB nom
 0.0%   0.0%   4.2KiB mime
 0.0%   0.0%   4.1KiB event_listener
 0.0%   0.0%   4.0KiB sha1
 0.0%   0.0%   3.9KiB regex_cache
 0.0%   0.0%   3.6KiB signal_hook_registry
 0.0%   0.0%   3.6KiB pwhash
 0.0%   0.0%   3.3KiB bincode
 0.0%   0.0%   3.2KiB tracing
 0.0%   0.0%   3.1KiB nu_ansi_term
 0.0%   0.0%   3.1KiB bcrypt
 0.0%   0.0%   3.0KiB webbrowser
 0.0%   0.0%   2.9KiB eyre
 0.0%   0.0%   2.7KiB libflate_lz77
 0.0%   0.0%   2.7KiB parking_lot_core
 0.0%   0.0%   2.6KiB uuid
 0.0%   0.0%   2.5KiB md5
 0.0%   0.0%   2.5KiB mio
 0.0%   0.0%   2.4KiB anstream
 0.0%   0.0%   2.4KiB rustls_native_certs
 0.0%   0.0%   2.3KiB form_urlencoded
 0.0%   0.0%   2.3KiB blowfish
 0.0%   0.0%   2.1KiB anstyle
 0.0%   0.0%   1.9KiB reqwest_middleware
 0.0%   0.0%   1.9KiB protox
 0.0%   0.0%   1.9KiB nvml_wrapper
 0.0%   0.0%   1.9KiB hyper_timeout
 0.0%   0.0%   1.9KiB strsim
 0.0%   0.0%   1.9KiB crossbeam_deque
 0.0%   0.0%   1.8KiB thread_local
 0.0%   0.0%   1.8KiB cache_control
 0.0%   0.0%   1.8KiB percent_encoding
 0.0%   0.0%   1.8KiB sct
 0.0%   0.0%   1.7KiB security_framework
 0.0%   0.0%   1.7KiB tokio_util
 0.0%   0.0%   1.7KiB rayon
 0.0%   0.0%   1.6KiB tracing_log
 0.0%   0.0%   1.6KiB smallvec
 0.0%   0.0%   1.6KiB tokio_stream
 0.0%   0.0%   1.5KiB futures_executor
 0.0%   0.0%   1.5KiB httpdate
 0.0%   0.0%   1.5KiB opentelemetry_appender_tracing
 0.0%   0.0%   1.4KiB spin
 0.0%   0.0%   1.4KiB libloading
 0.0%   0.0%   1.4KiB triomphe
 0.0%   0.0%   1.3KiB async_lock
 0.0%   0.0%   1.2KiB event_listener_strategy
 0.0%   0.0%   1.2KiB crc32fast
 0.0%   0.0%   1.0KiB miette
 0.0%   0.0%   1.0KiB fast_chemail
 0.0%   0.0%     932B getrandom
 0.0%   0.0%     928B headers
 0.0%   0.0%     908B indenter
 0.0%   0.0%     904B debugid
 0.0%   0.0%     856B core_foundation
 0.0%   0.0%     836B clap_lex
 0.0%   0.0%     788B uname
 0.0%   0.0%     652B tinyvec
 0.0%   0.0%     620B socket2
 0.0%   0.0%     620B serde_urlencoded
 0.0%   0.0%     600B linked_hash_map
 0.0%   0.0%     596B http_body
 0.0%   0.0%     548B quanta
 0.0%   0.0%     508B want
 0.0%   0.0%     408B rand
 0.0%   0.0%     396B parking
 0.0%   0.0%     376B bitvec
 0.0%   0.0%     332B slab
 0.0%   0.0%     324B ascii_utils
 0.0%   0.0%     268B headers_core
 0.0%   0.0%     260B zeroize
 0.0%   0.0%     248B tagptr
 0.0%   0.0%     184B log
 0.0%   0.0%     124B unicode_bidi
 0.0%   0.0%      96B untrusted
 0.0%   0.0%      20B subtle
 0.0%   0.0%       8B dyn_clone
57.8% 100.0%  30.0MiB .text section size, the file size is 51.9MiB

Note: numbers above are a result of guesswork. They are not 100% correct and never will be.

Summary by CodeRabbit

  • New Features

    • Integrated rquickjs for enhanced JavaScript runtime handling in Rust CLI applications, replacing deno_core.
    • Added conversion logic for JsRequest, JsResponse, and Command types to and from JavaScript values.
    • Modified the JavaScript console object to improve logging functionality.
  • Bug Fixes

    • Updated comparison operations in handle.rs for more accurate file path handling.
  • Refactor

    • Transitioned to rquickjs for JavaScript integration, affecting various components like requests, responses, and runtime management.
  • Tests

    • Added comprehensive tests for new conversions between Rust types and JavaScript objects.
  • Documentation

    • Enhanced inline comments and annotations for better clarity and maintenance of JavaScript integration code.

@github-actions github-actions bot added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Apr 12, 2024
@mayant15 mayant15 marked this pull request as ready for review April 16, 2024 06:31
Copy link
Contributor

coderabbitai bot commented Apr 16, 2024

Walkthrough

Walkthrough

The changes primarily involve transitioning from deno_core to rquickjs for JavaScript execution within the project, enhancing integration with QuickJS. This includes modifications to JavaScript request and response handling, and updates to runtime setup and built-in functions. The changes aim to improve performance and expand JavaScript functionalities in the system.

Changes

Files Summary of Changes
Cargo.toml, src/cli/.../runtime.rs Transition from deno_core to rquickjs, affecting dependencies and runtime setup.
src/cli/javascript/js_request.rs, src/cli/javascript/js_response.rs Enhanced JS request and response handling with QuickJS integration, including conversions and attribute modifications.
src/cli/javascript/request_filter.rs Added QuickJS conversion capabilities for command handling.
src/cli/javascript/shim/console.js Updated logging functions to use a new global function for message printing.
tailcall-cloudflare/src/handle.rs Simplified comparison logic by removing unnecessary borrowing.
examples/scripts/echo.js Modified to handle request transformation using a new Request object.

Assessment against linked issues

Objective Addressed Explanation
Migrate to QuickJS for JS execution (#1690) -
Ensure all existing tests pass (#1690) The confirmation of all tests being updated and passing is required.
Perform a benchmark to compare performance differences (#1690) No information provided regarding performance benchmarking.

Possibly related issues

  • Javascript Extensions API #1020: This issue discusses enhancing JavaScript functionalities and runtime, which aligns with the migration to rquickjs and the modifications in JavaScript handling seen in this PR. This could potentially address objectives related to improving JS runtime capabilities.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1b5c683 and 0b71b9f.
Files selected for processing (1)
  • src/cli/javascript/js_request.rs (5 hunks)
Additional Context Used
Path-based Instructions (1)
src/cli/javascript/js_request.rs (1)

Pattern **/*.rs: Programming Style Guidelines

  • When calling functions that do not need to modify values, pass references of those values.
  • When calling functions that need to modify values, pass ownership of the values, and ensure they are returned from the function.

IMPORTANT: This programming style may not be suitable for performance-sensitive components or hot code paths. In such cases, prioritize efficiency and optimization strategies to enhance performance.

Testing

  1. Write Tests: For every new feature or bugfix, ensure that you write appropriate tests.
    Structure your tests in the following way:

    use pretty_assertions::assert_eq;
    fn test_something_important() {
       let value = setup_something_using_a_function();
    
       let actual = perform_some_operation_on_the_value(value);
       let expected = ExpectedValue {foo: 1, bar: 2};
    
       assert_eq!(actual, expected);
    }
    • Setup the value using helper methods in tests.
    • Create an actual and an expected value.
    • Assert the two values in a new line.
    • Ensure there are only one assertions per test.
Additional comments not posted (1)
src/cli/javascript/js_request.rs (1)

14-41: The modifications to the JsRequest struct and its methods are well-implemented and maintain clean access to the underlying reqwest::Request.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

src/cli/javascript/runtime.rs Outdated Show resolved Hide resolved
src/cli/javascript/runtime.rs Outdated Show resolved Hide resolved
src/cli/javascript/runtime.rs Outdated Show resolved Hide resolved
Copy link

codecov bot commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 89.74943% with 45 lines in your changes are missing coverage. Please review.

Project coverage is 89.55%. Comparing base (51373fe) to head (0b71b9f).

Files Patch % Lines
src/cli/javascript/js_request.rs 87.25% 26 Missing ⚠️
src/cli/javascript/js_response.rs 93.51% 7 Missing ⚠️
src/cli/javascript/request_filter.rs 90.66% 7 Missing ⚠️
src/cli/javascript/runtime.rs 90.38% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1713      +/-   ##
==========================================
- Coverage   89.61%   89.55%   -0.06%     
==========================================
  Files         151      151              
  Lines       15547    15841     +294     
==========================================
+ Hits        13932    14186     +254     
- Misses       1615     1655      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tusharmath tusharmath marked this pull request as draft April 16, 2024 07:46
@mayant15 mayant15 requested a review from tusharmath April 17, 2024 01:17
@mayant15 mayant15 marked this pull request as ready for review April 17, 2024 01:17
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Comment on lines +33 to +34
#[rquickjs::function]
fn qjs_print(msg: String, is_err: bool) {
if is_err {
tracing::error!("{msg}");
} else {
tracing::info!("{msg}");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor qjs_print to handle potential errors in a more robust way.

Currently, qjs_print uses unconditional printing based on the is_err flag. Consider enhancing error handling by integrating with the logging framework or providing a mechanism to handle or report errors when printing fails.

fn qjs_print(msg: String, is_err: bool) {
    if is_err {
-       eprintln!("{msg}")
+       if let Err(e) = eprintln!("{msg}") {
+           log::error!("Failed to print error message: {}", e);
+       }
    } else {
-       println!("{msg}")
+       if let Err(e) = println!("{msg}") {
+           log::error!("Failed to print message: {}", e);
+       }
    }
}

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
#[rquickjs::function]
fn qjs_print(msg: String, is_err: bool) {
if is_err {
tracing::error!("{msg}");
} else {
tracing::info!("{msg}");
}
}
#[rquickjs::function]
fn qjs_print(msg: String, is_err: bool) {
if is_err {
if let Err(e) = eprintln!("{msg}") {
log::error!("Failed to print error message: {}", e);
}
} else {
if let Err(e) = println!("{msg}") {
log::error!("Failed to print message: {}", e);
}
}
}

src/cli/javascript/runtime.rs Show resolved Hide resolved
src/cli/javascript/js_response.rs Outdated Show resolved Hide resolved
Copy link

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. and removed state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. labels Apr 19, 2024
Copy link
Contributor

@meskill meskill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reason these changes not compiling for me when using rust v1.75.0. And with v1.77 it's fine

src/cli/javascript/runtime.rs Outdated Show resolved Hide resolved
src/cli/javascript/request_filter.rs Show resolved Hide resolved
Copy link

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Apr 21, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Out of diff range and nitpick comments (8)
examples/scripts/echo.js (1)

1-8: LGTM! Consider adding a comment explaining why a new Request object is created instead of modifying the existing one.

src/cli/javascript/runtime.rs (2)

52-60: The implementation of the LocalRuntime struct and its methods are robust and correctly handle the initialization of the new JS runtime. Consider adding more detailed logging within the try_new method to aid in debugging.


102-128: Utility functions such as prepare_args and call are correctly implemented with consistent error handling. Consider standardizing the format of error messages for consistency across the codebase.

src/cli/javascript/request_filter.rs (1)

98-154: The new tests for the FromJs implementation are comprehensive and well-structured. Consider adding comments to each test case to explain the specific scenario being tested.

src/cli/javascript/js_response.rs (2)

10-27: The modifications to the JsResponse struct for QuickJS integration are correctly implemented. Consider adding detailed documentation for the QuickJS methods to aid in understanding their usage.


135-179: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [65-178]

The tests for converting JsResponse to and from JavaScript objects are comprehensive and effectively cover various scenarios. Consider using more descriptive names for the tests to clarify their purpose.

src/cli/javascript/js_request.rs (2)

8-48: The modifications to the JsRequest and Uri structs for QuickJS integration are correctly implemented. Consider adding detailed documentation for the QuickJS methods to aid in understanding their usage.


188-253: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [142-252]

The tests for converting JsRequest and Uri to and from JavaScript objects are comprehensive and effectively cover various scenarios. Consider using more descriptive names for the tests to clarify their purpose.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

src/cli/javascript/request_filter.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label Apr 27, 2024
Copy link

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. and removed state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. labels Apr 29, 2024
examples/scripts/echo.js Outdated Show resolved Hide resolved
Copy link

github-actions bot commented May 2, 2024

Action required: PR inactive for 2 days.
Status update or closure in 5 days.

@github-actions github-actions bot added the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label May 2, 2024
@amitksingh1490 amitksingh1490 force-pushed the feat/quickjs branch 2 times, most recently from 83a8055 to 42bccb4 Compare May 4, 2024 05:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

src/cli/javascript/js_request.rs Outdated Show resolved Hide resolved
src/cli/javascript/js_request.rs Show resolved Hide resolved
@github-actions github-actions bot removed the state: inactive No current action needed/possible; issue fixed, out of scope, or superseded. label May 4, 2024
@amitksingh1490 amitksingh1490 force-pushed the feat/quickjs branch 2 times, most recently from 83a8055 to b895ff9 Compare May 4, 2024 07:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 17

src/cli/javascript/request_filter.rs Show resolved Hide resolved
src/cli/javascript/request_filter.rs Show resolved Hide resolved
src/cli/javascript/request_filter.rs Show resolved Hide resolved
src/cli/javascript/request_filter.rs Show resolved Hide resolved
src/cli/javascript/request_filter.rs Show resolved Hide resolved
src/cli/javascript/js_request.rs Outdated Show resolved Hide resolved
src/cli/javascript/js_request.rs Show resolved Hide resolved
src/cli/javascript/js_request.rs Show resolved Hide resolved
src/cli/javascript/js_request.rs Show resolved Hide resolved
src/cli/javascript/js_request.rs Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Out of diff range and nitpick comments (1)
src/cli/javascript/js_request.rs (1)

44-59: The conversion implementations for JsRequest are correct. Consider reviewing the performance impact of cloning in the TryFrom implementation, especially for large requests.

src/cli/javascript/js_request.rs Show resolved Hide resolved
src/cli/javascript/js_request.rs Show resolved Hide resolved
@tusharmath tusharmath changed the title feat(js): replace deno_core with rquickjs fix(js): replace deno_core with rquickjs May 4, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Out of diff range and nitpick comments (1)
src/cli/javascript/js_request.rs (1)

Line range hint 134-207: The IntoJs and FromJs implementations for Scheme and Uri handle conversions well. Consider improving the clarity of error messages.

- message: Some("unable to cast JS Value as object".to_string()),
+ message: Some("Expected JS Value to be an object but got another type".to_string()),

src/cli/javascript/js_request.rs Show resolved Hide resolved
@tusharmath tusharmath enabled auto-merge (squash) May 4, 2024 12:30
@tusharmath tusharmath disabled auto-merge May 4, 2024 12:40
@tusharmath tusharmath merged commit 10b2797 into tailcallhq:main May 4, 2024
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 Bounty claim type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: Use QuickJS instead of V8
4 participants