Skip to content

What are the differences between the js engine of this warehouse and quickjs? #120

@Misaka299

Description

@Misaka299

I need an embedded engine of a scripting language to provide scripting functions for my program. The script is mainly used to write crawlers. I chose js. But I ran into some problems when using this repository.

code:

use quick_js::{Context,JsValue};

fn main() {
    let context = Context::new().unwrap();

    let x = context.eval_as::<String>(r#"
        import * as std from "std";
        var file = std.open("std_open_file.js","w");
        file.puts("123");
        file.puts("456");
        file.puts("789");
        file.close();

        var x = 100 + 250; x.toString()
    "#).unwrap();
    println!("{}",x)
}

log:

C:/Users/Admin/.cargo/bin/cargo.exe run --color=always --package druid_view --example js
warning: unused manifest key: dependencies.druid.required-features
warning: unused import: `JsValue`
 --> examples\js.rs:1:24
  |
1 | use quick_js::{Context,JsValue};
  |                        ^^^^^^^
  |
  = note: \`#[warn(unused_imports)]\` on by default

warning: \`druid_view\` (example "js") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.21s
     Running \`target\debug\examples\js.exe\`
thread 'main' panicked at 'called \`Result::unwrap()\` on an \`Err\` value: Exception(String("SyntaxError: expecting \'(\'"))\', examples\js.rs:15:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\/library\std\src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\/library\core\src/panicking.rs:101:14
   2: core::result::unwrap_failed
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\/library\core\src/result.rs:1617:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\library\core\src/result.rs:1299:23
   4: js::main
             at .\examples\js.rs:6:13
   5: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\library\core\src\ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\examples\js.exe` (exit code: 101)

Process finished with exit code 101

and i can't use "console.log"

code:

use quick_js::{Context,JsValue};

fn main() {
    let context = Context::new().unwrap();

    let x = context.eval_as::<String>(r#"
        console.log("xxxxx");

        var x = 100 + 250; x.toString()
    "#).unwrap();
    println!("{}",x)
}

log:

C:/Users/Admin/.cargo/bin/cargo.exe run --color=always --package druid_view --example js
warning: unused manifest key: dependencies.druid.required-features
warning: unused import: `JsValue`
 --> examples\js.rs:1:24
  |
1 | use quick_js::{Context,JsValue};
  |                        ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: `druid_view` (example "js") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.19s
     Running `target\debug\examples\js.exe`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Exception(String("ReferenceError: 'console' is not defined"))', examples\js.rs:10:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\/library\std\src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\/library\core\src/panicking.rs:101:14
   2: core::result::unwrap_failed
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\/library\core\src/result.rs:1617:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\library\core\src/result.rs:1299:23
   4: js::main
             at .\examples\js.rs:6:13
   5: core::ops::function::FnOnce::call_once
             at /rustc/59eed8a2aac0230a8b53e89d4e99d55912ba6b35\library\core\src\ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: process didn't exit successfully: `target\debug\examples\js.exe` (exit code: 101)

Process finished with exit code 101

I want to add XPath support to it to improve productivity and reduce the threshold for writing crawlers.
I checked the "https://github.com/quickjs-zh/quickjs" document. I plan to use loadscript to use "https://github.com/google/wicked-good-xpath".
But I can't even use "console.log".

My ultimate goal is to add js script support to my program and the xpath in the script is used to write crawlers. How can I solve the problem I encountered? I want to know what are the differences between the js engine of this warehouse and quickjs? So that I can deal with the problems that I will encounter now and in the future.

who can help me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions