Skip to content

Commit 567bbd4

Browse files
committed
Add string
1 parent 5eda550 commit 567bbd4

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/js.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,24 @@ extern {
8686
#[wasm_bindgen(method, js_name = hasOwnProperty)]
8787
pub fn has_own_property(this: &Object, property: &str) -> bool;
8888
}
89+
90+
91+
// String
92+
#[wasm_bindgen]
93+
extern {
94+
pub type String;
95+
96+
/// The String global object is a constructor for strings or a sequence
97+
/// of characters.
98+
///
99+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
100+
#[wasm_bindgen(constructor)]
101+
pub fn new() -> String;
102+
103+
/// The length property of a String object indicates the length of a
104+
/// string, in UTF-16 code units.
105+
///
106+
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
107+
#[wasm_bindgen(method, js_name = length)]
108+
pub fn length(this: &String) -> i32;
109+
}

tests/all/js_globals/String.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![allow(non_snake_case)]
2+
3+
use project;
4+
5+
#[test]
6+
fn new() {
7+
project()
8+
.file("src/lib.rs", r#"
9+
#![feature(proc_macro, wasm_custom_section)]
10+
11+
extern crate wasm_bindgen;
12+
use wasm_bindgen::prelude::*;
13+
use wasm_bindgen::js;
14+
15+
#[wasm_bindgen]
16+
pub fn new_string() -> js::String {
17+
js::String::new()
18+
}
19+
"#)
20+
.file("test.ts", r#"
21+
import * as assert from "assert";
22+
import * as wasm from "./out";
23+
24+
export function test() {
25+
assert.equal(typeof wasm.new_string(), "string");
26+
}
27+
"#)
28+
.test()
29+
}

tests/all/js_globals/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use super::project;
44

55
mod Object;
6+
mod String;
67

78
#[test]
89
#[cfg(feature = "std")]

0 commit comments

Comments
 (0)