diff --git a/src/js.rs b/src/js.rs index 047acfff..0e1ed628 100644 --- a/src/js.rs +++ b/src/js.rs @@ -220,6 +220,14 @@ extern { #[wasm_bindgen(method, js_name = hasOwnProperty)] pub fn has_own_property(this: &Object, property: &JsValue) -> bool; + /// The toLocaleString() method returns a string representing the object. + /// This method is meant to be overridden by derived objects for locale-specific + /// purposes. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toLocaleString + #[wasm_bindgen(method, js_name = toLocaleString)] + pub fn to_locale_string(this: &Object) -> String; + /// The toString() method returns a string representing the object. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString diff --git a/tests/all/js_globals/Object.rs b/tests/all/js_globals/Object.rs index 86c3fb2b..6e2bbb70 100755 --- a/tests/all/js_globals/Object.rs +++ b/tests/all/js_globals/Object.rs @@ -157,3 +157,30 @@ fn property_is_enumerable() { "#) .test() } + +#[test] +fn to_locale_string() { + project() + .file("src/lib.rs", r#" + #![feature(proc_macro, wasm_custom_section)] + + extern crate wasm_bindgen; + use wasm_bindgen::prelude::*; + use wasm_bindgen::js; + + #[wasm_bindgen] + pub fn to_locale_string() -> String { + let object = js::Object::new(); + object.to_locale_string() + } + "#) + .file("test.ts", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.to_locale_string(), "[object Object]"); + } + "#) + .test() +}