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

How might you call console.log? #226

Closed
ctaggart opened this issue Aug 20, 2017 · 4 comments
Closed

How might you call console.log? #226

ctaggart opened this issue Aug 20, 2017 · 4 comments
Labels

Comments

@ctaggart
Copy link

console is a global object in Node.js. How would I get a reference to it, so that I could call the .log function`?

Background: I want to play with a the TypeScript library from Neon, but need help getting started with Neon.

@ctaggart
Copy link
Author

@dherman, pretty please.

@ctaggart
Copy link
Author

I closed this thinking that I would be able to use the chakracore-rs library, but that didn't work out. I'm reopening this, hoping that I can get some help learning to use it.

@ctaggart ctaggart reopened this Sep 22, 2017
@dherman
Copy link
Collaborator

dherman commented Sep 22, 2017

OK, the API that's missing is the ability to get to the current global object -- filed as #249. From there you can pull off the console object and extract the log method. (We should also add conveniences to eliminate some of the tedium of all those steps.)

@dherman
Copy link
Collaborator

dherman commented Oct 11, 2017

Fixed in #253:

pub fn call_console_log(call: Call) -> JsResult<JsObject> {
    let scope = call.scope;
    
    let global = scope.global();
    let console = global.get(scope, "console")?.check::<JsObject>()?;
    let log = console.get(scope, "log")?.check::<JsFunction>()?;
    let args: Vec<Handle<JsString>> = vec![JsString::new(scope, "hello world").unwrap()];
    log.call(scope, console, args.into_iter())?;
    // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants