File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -347,6 +347,13 @@ extern {
347
347
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
348
348
#[ wasm_bindgen( method, js_class = "String" ) ]
349
349
pub fn slice ( this : & JsString , start : u32 , end : u32 ) -> JsString ;
350
+
351
+ /// The String object's charAt() method returns a new string consisting of the single
352
+ /// UTF-16 code unit located at the specified offset into the string.
353
+ ///
354
+ /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt
355
+ #[ wasm_bindgen( method, js_class = "String" , js_name = charAt) ]
356
+ pub fn char_at ( this : & JsString , index : u32 ) -> JsString ;
350
357
}
351
358
352
359
impl < ' a > From < & ' a str > for JsString {
Original file line number Diff line number Diff line change 2
2
3
3
use project;
4
4
5
+ #[ test]
6
+ fn char_at ( ) {
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 string_char_at(this: &js::JsString, index: u32) -> js::JsString {
17
+ this.char_at(index)
18
+ }
19
+ "# )
20
+ . file ( "test.ts" , r#"
21
+ import * as assert from "assert";
22
+ import * as wasm from "./out";
23
+
24
+ var anyString = 'Brave new world';
25
+
26
+ export function test() {
27
+ assert.equal(wasm.string_char_at(anyString, 0), "B");
28
+ assert.equal(wasm.string_char_at(anyString, 999), "");
29
+ }
30
+ "# )
31
+ . test ( )
32
+ }
33
+
5
34
#[ test]
6
35
fn slice ( ) {
7
36
project ( )
You can’t perform that action at this time.
0 commit comments