-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from jameslahm/refactor-js-class
Refactor use Js Builtins
- Loading branch information
Showing
30 changed files
with
1,047 additions
and
1,102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,42 @@ | ||
use std::fs::read_to_string; | ||
|
||
use starlight::{prelude::Options, Platform}; | ||
use starlight::{ | ||
prelude::{JsHint, JsValue, Options}, | ||
Platform, | ||
}; | ||
|
||
fn main() { | ||
Platform::initialize(); | ||
let mut runtime = Platform::new_runtime(Options::default(), None); | ||
let ctx = runtime.new_context(); | ||
|
||
let content = read_to_string("examples/hello-world.js").unwrap(); | ||
let res = ctx.eval_internal(None, false, &content, false); | ||
|
||
match res { | ||
Ok(val) => { | ||
val.to_string(ctx).unwrap_or_else(|_| String::new()); | ||
} | ||
Err(e) => println!( | ||
"Uncaught {}", | ||
e.to_string(ctx).unwrap_or_else(|_| String::new()) | ||
), | ||
}; | ||
let mut ctx = runtime.new_context(); | ||
|
||
let prototype = ctx | ||
.global_object() | ||
.get(ctx, "Object") | ||
.unwrap() | ||
.to_object(ctx) | ||
.unwrap() | ||
.get(ctx, "prototype") | ||
.unwrap(); | ||
let func = prototype | ||
.to_object(ctx) | ||
.unwrap() | ||
.get(ctx, "hasOwnProperty") | ||
.unwrap() | ||
.to_object(ctx) | ||
.unwrap(); | ||
|
||
let structure = ctx.global_data().get_function_struct(); | ||
let prototype = structure.prototype(); | ||
|
||
println!("{:?}", JsValue::new(structure)); | ||
println!("{:?}", JsValue::new(*prototype.unwrap())); | ||
|
||
let structure = func.structure(); | ||
let prototype = structure.prototype(); | ||
|
||
println!("{:?}", JsValue::new(structure)); | ||
|
||
println!("{:?}", JsValue::new(*prototype.unwrap())); | ||
ctx.eval("print(Object.prototype.hasOwnProperty)").unwrap(); | ||
} |
Oops, something went wrong.