implements Object.prototype.toLocaleString() binding

This commit is contained in:
belfz 2018-06-22 13:36:44 +02:00
parent 9e01e67aa3
commit 39465c896c
2 changed files with 35 additions and 0 deletions

View File

@ -105,6 +105,14 @@ extern {
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/propertyIsEnumerable
#[wasm_bindgen(method, js_name = propertyIsEnumerable)]
pub fn property_is_enumerable(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;
}
// Array

View File

@ -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()
}