File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -255,3 +255,17 @@ extern {
255
255
#[ wasm_bindgen( method, js_name = propertyIsEnumerable) ]
256
256
pub fn property_is_enumerable ( this : & Object , property : & JsValue ) -> bool ;
257
257
}
258
+
259
+ // String
260
+ #[ wasm_bindgen]
261
+ extern {
262
+ #[ wasm_bindgen( js_name = String ) ]
263
+ pub type JsString ;
264
+
265
+ /// The slice() method extracts a section of a string and returns it as a
266
+ /// new string, without modifying the original string.
267
+ ///
268
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
269
+ #[ wasm_bindgen( method, js_class = "String" ) ]
270
+ pub fn slice ( this : & JsString , start : u32 , end : u32 ) -> JsString ;
271
+ }
Original file line number Diff line number Diff line change
1
+ #![ allow( non_snake_case) ]
2
+
3
+ use project;
4
+
5
+ #[ test]
6
+ fn slice ( ) {
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 create_slice(this: &js::JsString, start: u32, end: u32) -> js::JsString {
17
+ this.slice(start, end)
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
+ let characters = "acxn18";
26
+ let subset = wasm.create_slice(characters, 1, 3);
27
+
28
+ assert.equal(subset, "cx");
29
+ }
30
+ "# )
31
+ . test ( )
32
+ }
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ use super::project;
5
5
mod Object ;
6
6
mod Array ;
7
7
mod ArrayIterator ;
8
+ mod JsString ;
8
9
9
10
#[ test]
10
11
#[ cfg( feature = "std" ) ]
You can’t perform that action at this time.
0 commit comments