From 592d426e4f1af0dc68fe0a0ab7e221f503724406 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 11:43:34 +0200 Subject: [PATCH 01/19] feat: add Reflect.apply --- src/js.rs | 12 ++++++++++ tests/all/js_globals/Reflect.rs | 41 +++++++++++++++++++++++++++++++++ tests/all/js_globals/mod.rs | 1 + 3 files changed, 54 insertions(+) create mode 100644 tests/all/js_globals/Reflect.rs diff --git a/src/js.rs b/src/js.rs index c980f1b6..46b0459b 100644 --- a/src/js.rs +++ b/src/js.rs @@ -978,6 +978,18 @@ extern "C" { pub fn values(object: &Object) -> Array; } +// Reflect +#[wasm_bindgen] +extern "C" { + pub type Reflect; + + /// The static Reflect.apply() method calls a target function with arguments as specified. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply + #[wasm_bindgen(static_method_of = Reflect, catch)] + pub fn apply(target: &Function, this_argument: &JsValue, arguments_list: &Array) -> Result; +} + // Set #[wasm_bindgen] extern { diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs new file mode 100644 index 00000000..c9b39bb2 --- /dev/null +++ b/tests/all/js_globals/Reflect.rs @@ -0,0 +1,41 @@ +#![allow(non_snake_case)] + +use project; + +#[test] +fn apply() { + 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 apply(target: &js::Function, this_argument: &JsValue, arguments_list: &js::Array) -> JsValue { + let result = js::Reflect::apply(target, this_argument, arguments_list); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.apply(''.charAt, 'ponies', [3]), 'i'); + assert.equal(wasm.apply('', 'ponies', [3]), "TypeError"); + } + "#, + ) + .test() +} \ No newline at end of file diff --git a/tests/all/js_globals/mod.rs b/tests/all/js_globals/mod.rs index 8c02811c..097d514e 100644 --- a/tests/all/js_globals/mod.rs +++ b/tests/all/js_globals/mod.rs @@ -15,6 +15,7 @@ mod MapIterator; mod Math; mod Number; mod Object; +mod Reflect; mod Set; mod SetIterator; mod TypedArray; From 13b3b0d87ac1ec73361b6da2f914b7bae9a4cb6b Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:07:02 +0200 Subject: [PATCH 02/19] feat: add Reflect.construct --- src/js.rs | 10 +++ tests/all/js_globals/Reflect.rs | 125 ++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) diff --git a/src/js.rs b/src/js.rs index 46b0459b..e1d43b74 100644 --- a/src/js.rs +++ b/src/js.rs @@ -988,6 +988,16 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply #[wasm_bindgen(static_method_of = Reflect, catch)] pub fn apply(target: &Function, this_argument: &JsValue, arguments_list: &Array) -> Result; + + /// The static Reflect.construct() method acts like the new operator, but as a function. + /// It is equivalent to calling new target(...args). It gives also the added option to + /// specify a different prototype. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct + #[wasm_bindgen(static_method_of = Reflect, catch)] + pub fn construct(target: &Function, arguments_list: &Array) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = construct, catch)] + pub fn construct_with_new_target(target: &Function, arguments_list: &Array, new_target: &Function) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index c9b39bb2..7fb12670 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -38,4 +38,129 @@ fn apply() { "#, ) .test() +} + +#[test] +fn construct() { + 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 construct(target: &js::Function, arguments_list: &js::Array) -> JsValue { + let result = js::Reflect::construct(target, arguments_list); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + class Rectangle { + public x: number; + public y: number; + + constructor(x: number, y: number){ + this.x = x, + this.y = y + } + + static eq(x: number, y: number) { + return x === y; + } + + } + + const args = [10, 10]; + + assert.equal(wasm.construct(Rectangle, args).x, 10); + assert.equal(wasm.construct('', args), "TypeError"); + } + "#, + ) + .test() +} + +#[test] +fn construct_with_new_target() { + 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 construct_with_new_target(target: &js::Function, arguments_list: &js::Array, new_target: &js::Function) -> JsValue { + let result = js::Reflect::construct_with_new_target(target, arguments_list, new_target); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + class Rectangle { + public x: number; + public y: number; + + constructor(x: number, y: number){ + this.x = x, + this.y = y + } + + static eq(x: number, y: number) { + return x === y; + } + + } + + class Rectangle2 { + public x: number; + public y: number; + + constructor(x: number, y: number){ + this.x = x, + this.y = y + } + + static eq(x: number, y: number) { + return x === y; + } + + } + + const args = [10, 10]; + + assert.equal(wasm.construct_with_new_target(Rectangle, args, Rectangle2).x, 10); + assert.equal(wasm.construct_with_new_target(Rectangle, args, ''), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From 07a726b9dc0dd2410fc6732fe0fd9b06a5883027 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:17:01 +0200 Subject: [PATCH 03/19] feat: add Reflect.defineProperty --- src/js.rs | 7 ++++++ tests/all/js_globals/Reflect.rs | 40 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/js.rs b/src/js.rs index e1d43b74..51d5fc4f 100644 --- a/src/js.rs +++ b/src/js.rs @@ -998,6 +998,13 @@ extern "C" { pub fn construct(target: &Function, arguments_list: &Array) -> Result; #[wasm_bindgen(static_method_of = Reflect, js_name = construct, catch)] pub fn construct_with_new_target(target: &Function, arguments_list: &Array, new_target: &Function) -> Result; + + /// The static Reflect.defineProperty() method is like Object.defineProperty() + /// but returns a Boolean. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty + #[wasm_bindgen(static_method_of = Reflect, js_name = defineProperty, catch)] + pub fn define_property(target: &Object, property_key: &JsString, attributes: &Object) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 7fb12670..906b350d 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -163,4 +163,44 @@ fn construct_with_new_target() { "#, ) .test() +} + +#[test] +fn define_property() { + 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 define_property(target: &js::Object, property_key: &js::JsString, attributes: &js::Object) -> JsValue { + let result = js::Reflect::define_property(target, property_key, attributes); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = {}; + + assert.equal(wasm.define_property(object, "key", { value: 42}), true) + assert.equal(wasm.define_property("", "key", { value: 42 }), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From 5fa18f8f40c34fdbd07d95c42f2fb08d9ffe6fcf Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:24:52 +0200 Subject: [PATCH 04/19] feat: add Reflect.deleteProperty --- src/js.rs | 9 ++++++- tests/all/js_globals/Reflect.rs | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/js.rs b/src/js.rs index 51d5fc4f..30a2dab6 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1004,7 +1004,14 @@ extern "C" { /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty #[wasm_bindgen(static_method_of = Reflect, js_name = defineProperty, catch)] - pub fn define_property(target: &Object, property_key: &JsString, attributes: &Object) -> Result; + pub fn define_property(target: &Object, property_key: &JsValue, attributes: &Object) -> Result; + + /// The static Reflect.deleteProperty() method allows to delete properties. + /// It is like the delete operator as a function. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty + #[wasm_bindgen(static_method_of = Reflect, js_name = deleteProperty, catch)] + pub fn delete_property(target: &JsValue, key: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 906b350d..19dcec43 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -203,4 +203,52 @@ fn define_property() { "#, ) .test() +} + +#[test] +fn delete_property() { + 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 delete_property(target: &JsValue, property_key: &JsValue) -> JsValue { + let result = js::Reflect::delete_property(target, property_key); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + + wasm.delete_property(object, 'property'); + + assert.equal(object.property, undefined); + + const array = [1, 2, 3, 4, 5]; + wasm.delete_property(array, 3); + + assert.equal(array[3], undefined); + } + "#, + ) + .test() } \ No newline at end of file From 3ba00bc13c730edf5fcf570126542491e83487f2 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:31:24 +0200 Subject: [PATCH 05/19] feat: add Reflect.get --- src/js.rs | 7 ++++ tests/all/js_globals/Reflect.rs | 61 +++++++++++++++++++++++++++++---- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/js.rs b/src/js.rs index 30a2dab6..436b08e8 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1012,6 +1012,13 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty #[wasm_bindgen(static_method_of = Reflect, js_name = deleteProperty, catch)] pub fn delete_property(target: &JsValue, key: &JsValue) -> Result; + + /// The static Reflect.get() method works like getting a property from + /// an object (target[propertyKey]) as a function. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get + #[wasm_bindgen(static_method_of = Reflect, catch)] + pub fn get(target: &JsValue, key: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 19dcec43..5f43c93a 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -32,8 +32,8 @@ fn apply() { import * as wasm from "./out"; export function test() { - assert.equal(wasm.apply(''.charAt, 'ponies', [3]), 'i'); - assert.equal(wasm.apply('', 'ponies', [3]), "TypeError"); + assert.equal(wasm.apply("".charAt, "ponies", [3]), "i"); + assert.equal(wasm.apply("", "ponies", [3]), "TypeError"); } "#, ) @@ -88,7 +88,7 @@ fn construct() { const args = [10, 10]; assert.equal(wasm.construct(Rectangle, args).x, 10); - assert.equal(wasm.construct('', args), "TypeError"); + assert.equal(wasm.construct("", args), "TypeError"); } "#, ) @@ -158,7 +158,7 @@ fn construct_with_new_target() { const args = [10, 10]; assert.equal(wasm.construct_with_new_target(Rectangle, args, Rectangle2).x, 10); - assert.equal(wasm.construct_with_new_target(Rectangle, args, ''), "TypeError"); + assert.equal(wasm.construct_with_new_target(Rectangle, args, ""), "TypeError"); } "#, ) @@ -178,7 +178,7 @@ fn define_property() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn define_property(target: &js::Object, property_key: &js::JsString, attributes: &js::Object) -> JsValue { + pub fn define_property(target: &js::Object, property_key: &JsValue, attributes: &js::Object) -> JsValue { let result = js::Reflect::define_property(target, property_key, attributes); let result = match result { Ok(val) => val, @@ -239,7 +239,7 @@ fn delete_property() { property: 42 }; - wasm.delete_property(object, 'property'); + wasm.delete_property(object, "property"); assert.equal(object.property, undefined); @@ -247,6 +247,55 @@ fn delete_property() { wasm.delete_property(array, 3); assert.equal(array[3], undefined); + + assert.equal(wasm.delete_property("", 3), "TypeError"); + } + "#, + ) + .test() +} + +#[test] +fn get() { + 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 get(target: &JsValue, property_key: &JsValue) -> JsValue { + let result = js::Reflect::get(target, property_key); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + + assert.equal(wasm.get(object, "property"), 42); + + const array = [1, 2, 3, 4, 5]; + + assert.equal(wasm.get(array, 3), 4); + + assert.equal(wasm.get("", 3), "TypeError"); } "#, ) From 2422c5e9450237ddf0eae37d19bb3632e9e7fd5b Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:35:40 +0200 Subject: [PATCH 06/19] feat: add Reflect.getOwnPropertyDescriptor --- src/js.rs | 8 ++++++ tests/all/js_globals/Reflect.rs | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/js.rs b/src/js.rs index 436b08e8..499fefcd 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1019,6 +1019,14 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get #[wasm_bindgen(static_method_of = Reflect, catch)] pub fn get(target: &JsValue, key: &JsValue) -> Result; + + /// The static Reflect.getOwnPropertyDescriptor() method is similar to + /// Object.getOwnPropertyDescriptor(). It returns a property descriptor + /// of the given property if it exists on the object, undefined otherwise. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor + #[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)] + pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 5f43c93a..7d730885 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -300,4 +300,47 @@ fn get() { "#, ) .test() +} + +#[test] +fn get_own_property_descriptor() { + 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 get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> JsValue { + let result = js::Reflect::get_own_property_descriptor(target, property_key); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + + assert.equal(wasm.get_own_property_descriptor(object, "property").value, 42); + assert.equal(wasm.get_own_property_descriptor(object, "property1"), undefined); + assert.equal(wasm.get_own_property_descriptor("", "property1"), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From edddd4b08e051b571de832d0f5c67c5c1bf3f6e7 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:39:56 +0200 Subject: [PATCH 07/19] feat: add Reflect.getPrototypeOf --- src/js.rs | 9 +++++++ tests/all/js_globals/Reflect.rs | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/js.rs b/src/js.rs index 499fefcd..849c75a1 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1027,6 +1027,15 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor #[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)] pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> Result; + + /// The static Reflect.getPrototypeOf() method is almost the same + /// method as Object.getPrototypeOf(). It returns the prototype + /// (i.e. the value of the internal [[Prototype]] property) of + /// the specified object. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf + #[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf, catch)] + pub fn get_prototype_of(target: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 7d730885..5f676576 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -343,4 +343,48 @@ fn get_own_property_descriptor() { "#, ) .test() +} + +#[test] +fn get_prototype_of() { + 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 get_prototype_of(target: &JsValue) -> JsValue { + let result = js::Reflect::get_prototype_of(target); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + const array: number[] = [1, 2, 3]; + + assert.equal(wasm.get_prototype_of(object), Object.prototype); + assert.equal(wasm.get_prototype_of(array), Array.prototype); + assert.equal(wasm.get_prototype_of(""), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From 7c297ccfb405445c9e03ee38798f0155d67e83b5 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:44:49 +0200 Subject: [PATCH 08/19] feat: add Reflect.has --- src/js.rs | 6 +++++ tests/all/js_globals/Reflect.rs | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/js.rs b/src/js.rs index 849c75a1..9ed038c1 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1036,6 +1036,12 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf #[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf, catch)] pub fn get_prototype_of(target: &JsValue) -> Result; + + /// The static Reflect.has() method works like the in operator as a function. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has + #[wasm_bindgen(static_method_of = Reflect, catch)] + pub fn has(target: &JsValue, property_key: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 5f676576..9e572877 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -387,4 +387,50 @@ fn get_prototype_of() { "#, ) .test() +} + +#[test] +fn has() { + 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 has(target: &JsValue, property_key: &JsValue) -> JsValue { + let result = js::Reflect::has(target, property_key); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + const array: number[] = [1, 2, 3, 4] + + assert.equal(wasm.has(object, "property"), true); + assert.equal(wasm.has(object, "foo"), false); + assert.equal(wasm.has(array, 3), true); + assert.equal(wasm.has(array, 10), false); + assert.equal(wasm.has("", "property"), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From eb245d550318fee521f453dd5f69f06ff01a4383 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:49:07 +0200 Subject: [PATCH 09/19] feat: add Reflect.isExtensible --- src/js.rs | 8 ++++++ tests/all/js_globals/Reflect.rs | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/js.rs b/src/js.rs index 9ed038c1..fcf9bc85 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1042,6 +1042,14 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has #[wasm_bindgen(static_method_of = Reflect, catch)] pub fn has(target: &JsValue, property_key: &JsValue) -> Result; + + /// The static Reflect.isExtensible() method determines if an object is extensible + /// (whether it can have new properties added to it). It is similar to + /// Object.isExtensible(), but with some differences. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible + #[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible, catch)] + pub fn is_extensible(target: &Object) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 9e572877..50ee68d8 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -433,4 +433,54 @@ fn has() { "#, ) .test() +} + +#[test] +fn is_extensible() { + 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 is_extensible(target: &js::Object) -> JsValue { + let result = js::Reflect::is_extensible(target); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + + assert.equal(wasm.is_extensible(object), true); + + Reflect.preventExtensions(object); + + assert.equal(wasm.is_extensible(object), false); + + const object2 = Object.seal({}); + + assert.equal(wasm.is_extensible(object2), false); + assert.equal(wasm.is_extensible(""), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From e36f982391efdeb88af3419a4d5efee1287c6385 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:53:38 +0200 Subject: [PATCH 10/19] feat: add Reflect.ownKeys --- src/js.rs | 9 ++++++- tests/all/js_globals/Reflect.rs | 45 +++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/js.rs b/src/js.rs index fcf9bc85..a85a879c 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1041,7 +1041,7 @@ extern "C" { /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn has(target: &JsValue, property_key: &JsValue) -> Result; + pub fn has(target: &JsValue, property_key: &JsValue) -> Result; /// The static Reflect.isExtensible() method determines if an object is extensible /// (whether it can have new properties added to it). It is similar to @@ -1050,6 +1050,13 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible #[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible, catch)] pub fn is_extensible(target: &Object) -> Result; + + /// The static Reflect.ownKeys() method returns an array of the + /// target object's own property keys. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys + #[wasm_bindgen(static_method_of = Reflect, js_name = ownKeys, catch)] + pub fn own_keys(target: &Object) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 50ee68d8..1269f402 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -483,4 +483,49 @@ fn is_extensible() { "#, ) .test() +} + +#[test] +fn own_keys() { + 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 own_keys(target: &js::Object) -> JsValue { + let result = js::Reflect::own_keys(target); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = { + property: 42 + }; + const array: number[] = []; + + assert.equal(wasm.own_keys(object)[0], "property"); + assert.equal(wasm.own_keys(array)[0], "length"); + + assert.equal(wasm.own_keys(""), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From fc82ba4ec30463cb40ece917744ee304dadeabe8 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 12:56:37 +0200 Subject: [PATCH 11/19] feat: add Reflect.preventExtensions --- src/js.rs | 9 ++++++++ tests/all/js_globals/Reflect.rs | 41 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/js.rs b/src/js.rs index a85a879c..34f30169 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1057,6 +1057,15 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys #[wasm_bindgen(static_method_of = Reflect, js_name = ownKeys, catch)] pub fn own_keys(target: &Object) -> Result; + + /// The static Reflect.preventExtensions() method prevents new + /// properties from ever being added to an object (i.e. prevents + /// future extensions to the object). It is similar to + /// Object.preventExtensions(), but with some differences. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions + #[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions, catch)] + pub fn prevent_extensions(target: &Object) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 1269f402..0ad3945f 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -528,4 +528,45 @@ fn own_keys() { "#, ) .test() +} + +#[test] +fn prevent_extensions() { + 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 prevent_extensions(target: &js::Object) -> JsValue { + let result = js::Reflect::prevent_extensions(target); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + var object1 = {}; + + wasm.prevent_extensions(object1); + + assert.equal(Reflect.isExtensible(object1), false); + } + "#, + ) + .test() } \ No newline at end of file From eb3f67a36f426bc3d8238832e85eb38e82c160f9 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 13:08:43 +0200 Subject: [PATCH 12/19] feat: add Reflect.set --- src/js.rs | 9 ++++ tests/all/js_globals/Reflect.rs | 90 ++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/js.rs b/src/js.rs index 34f30169..d2c8eada 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1066,6 +1066,15 @@ extern "C" { /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions #[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions, catch)] pub fn prevent_extensions(target: &Object) -> Result; + + /// The static Reflect.set() method works like setting a + /// property on an object. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set + #[wasm_bindgen(static_method_of = Reflect, catch)] + pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = set, catch)] + pub fn set_with_receiver(target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 0ad3945f..5f9f5b31 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -560,7 +560,7 @@ fn prevent_extensions() { import * as wasm from "./out"; export function test() { - var object1 = {}; + const object1 = {}; wasm.prevent_extensions(object1); @@ -569,4 +569,92 @@ fn prevent_extensions() { "#, ) .test() +} + +#[test] +fn set() { + 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 set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> JsValue { + let result = js::Reflect::set(target, property_key, value); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = {}; + const array: number[] = [1, 2, 3, 4]; + assert.equal(wasm.set(object, "key", "value"), true); + assert.equal(wasm.set(array, 0, 100), true); + + assert.equal(Reflect.get(object, "key"), "value"); + assert.equal(array[0], 100); + assert.equal(wasm.set("", "key", "value"), "TypeError"); + } + "#, + ) + .test() +} + +#[test] +fn set_with_receiver() { + 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 set_with_receiver(target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue) -> JsValue { + let result = js::Reflect::set_with_receiver(target, property_key, value, receiver); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = {}; + const array: number[] = [1, 2, 3, 4]; + assert.equal(wasm.set_with_receiver({}, "key", "value", object), true); + assert.equal(wasm.set_with_receiver([], 0, 100, array), true); + + assert.equal(Reflect.get(object, "key"), "value"); + assert.equal(array[0], 100); + assert.equal(wasm.set_with_receiver("", "key", "value", ""), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From 1397f9b05a011f312e71050ec3fce54fcecf456f Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 13:13:35 +0200 Subject: [PATCH 13/19] feat: add Reflect.setPrototypeOf --- src/js.rs | 9 +++++++ tests/all/js_globals/Reflect.rs | 43 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/js.rs b/src/js.rs index d2c8eada..38ade1dd 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1075,6 +1075,15 @@ extern "C" { pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result; #[wasm_bindgen(static_method_of = Reflect, js_name = set, catch)] pub fn set_with_receiver(target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue) -> Result; + + /// The static Reflect.setPrototypeOf() method is the same + /// method as Object.setPrototypeOf(). It sets the prototype + /// (i.e., the internal [[Prototype]] property) of a specified + /// object to another object or to null. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf + #[wasm_bindgen(static_method_of = Reflect, js_name = setPrototypeOf, catch)] + pub fn set_prototype_of(target: &JsValue, prototype: &JsValue) -> Result; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 5f9f5b31..6bf2e212 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -657,4 +657,47 @@ fn set_with_receiver() { "#, ) .test() +} + +#[test] +fn set_prototype_of() { + 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 set_prototype_of(target: &JsValue, prototype: &JsValue) -> JsValue { + let result = js::Reflect::set_prototype_of(target, prototype); + let result = match result { + Ok(val) => val, + Err(_err) => "TypeError".into() + }; + result + } + "#, + ) + .file( + "test.ts", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + const object = {}; + assert.equal(wasm.set_prototype_of(object, Object.prototype), true); + assert.equal(Object.getPrototypeOf(object), Object.prototype); + assert.equal(wasm.set_prototype_of(object, null), true); + assert.equal(Object.getPrototypeOf(object), null); + + assert.equal(wasm.set_prototype_of("", Object.prototype), "TypeError"); + } + "#, + ) + .test() } \ No newline at end of file From 3442f9d9d72b307aa0fc691319004813a50f373d Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 13:18:06 +0200 Subject: [PATCH 14/19] fix: Reflect.has --- src/js.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js.rs b/src/js.rs index 38ade1dd..7b54aa02 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1041,7 +1041,7 @@ extern "C" { /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn has(target: &JsValue, property_key: &JsValue) -> Result; + pub fn has(target: &JsValue, property_key: &JsValue) -> Result; /// The static Reflect.isExtensible() method determines if an object is extensible /// (whether it can have new properties added to it). It is similar to From 008f17143b4a2eef38fb2672fc8c50d360155b6f Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 15:32:34 +0200 Subject: [PATCH 15/19] fix: Reflect.has target should be &Object --- src/js.rs | 4 ++-- tests/all/js_globals/Reflect.rs | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/js.rs b/src/js.rs index 7b54aa02..34f32443 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1040,8 +1040,8 @@ extern "C" { /// The static Reflect.has() method works like the in operator as a function. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/has - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn has(target: &JsValue, property_key: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect)] + pub fn has(target: &Object, property_key: &JsValue) -> bool; /// The static Reflect.isExtensible() method determines if an object is extensible /// (whether it can have new properties added to it). It is similar to diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 6bf2e212..49d45cde 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -402,13 +402,8 @@ fn has() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn has(target: &JsValue, property_key: &JsValue) -> JsValue { - let result = js::Reflect::has(target, property_key); - let result = match result { - Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + pub fn has(target: &js::Object, property_key: &JsValue) -> bool { + js::Reflect::has(target, property_key) } "#, ) @@ -428,7 +423,6 @@ fn has() { assert.equal(wasm.has(object, "foo"), false); assert.equal(wasm.has(array, 3), true); assert.equal(wasm.has(array, 10), false); - assert.equal(wasm.has("", "property"), "TypeError"); } "#, ) From 40b7b069bcbd7544c84eecaacde0527b3363ad55 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 15:52:12 +0200 Subject: [PATCH 16/19] fix: return actual error message --- tests/all/js_globals/Reflect.rs | 136 ++++++++++++++++---------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 49d45cde..7877e9db 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -17,11 +17,11 @@ fn apply() { #[wasm_bindgen] pub fn apply(target: &js::Function, this_argument: &JsValue, arguments_list: &js::Array) -> JsValue { let result = js::Reflect::apply(target, this_argument, arguments_list); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -33,7 +33,7 @@ fn apply() { export function test() { assert.equal(wasm.apply("".charAt, "ponies", [3]), "i"); - assert.equal(wasm.apply("", "ponies", [3]), "TypeError"); + assert.equal(wasm.apply("", "ponies", [3]), "TypeError: Function.prototype.apply was called on , which is a string and not a function"); } "#, ) @@ -55,11 +55,11 @@ fn construct() { #[wasm_bindgen] pub fn construct(target: &js::Function, arguments_list: &js::Array) -> JsValue { let result = js::Reflect::construct(target, arguments_list); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -88,7 +88,7 @@ fn construct() { const args = [10, 10]; assert.equal(wasm.construct(Rectangle, args).x, 10); - assert.equal(wasm.construct("", args), "TypeError"); + assert.equal(wasm.construct("", args), "TypeError: is not a constructor"); } "#, ) @@ -110,11 +110,11 @@ fn construct_with_new_target() { #[wasm_bindgen] pub fn construct_with_new_target(target: &js::Function, arguments_list: &js::Array, new_target: &js::Function) -> JsValue { let result = js::Reflect::construct_with_new_target(target, arguments_list, new_target); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -158,7 +158,7 @@ fn construct_with_new_target() { const args = [10, 10]; assert.equal(wasm.construct_with_new_target(Rectangle, args, Rectangle2).x, 10); - assert.equal(wasm.construct_with_new_target(Rectangle, args, ""), "TypeError"); + assert.equal(wasm.construct_with_new_target(Rectangle, args, ""), "TypeError: is not a constructor"); } "#, ) @@ -180,11 +180,11 @@ fn define_property() { #[wasm_bindgen] pub fn define_property(target: &js::Object, property_key: &JsValue, attributes: &js::Object) -> JsValue { let result = js::Reflect::define_property(target, property_key, attributes); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -198,7 +198,7 @@ fn define_property() { const object = {}; assert.equal(wasm.define_property(object, "key", { value: 42}), true) - assert.equal(wasm.define_property("", "key", { value: 42 }), "TypeError"); + assert.equal(wasm.define_property("", "key", { value: 42 }), "TypeError: Reflect.defineProperty called on non-object"); } "#, ) @@ -220,11 +220,11 @@ fn delete_property() { #[wasm_bindgen] pub fn delete_property(target: &JsValue, property_key: &JsValue) -> JsValue { let result = js::Reflect::delete_property(target, property_key); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -248,7 +248,7 @@ fn delete_property() { assert.equal(array[3], undefined); - assert.equal(wasm.delete_property("", 3), "TypeError"); + assert.equal(wasm.delete_property("", 3), "TypeError: Reflect.deleteProperty called on non-object"); } "#, ) @@ -270,11 +270,11 @@ fn get() { #[wasm_bindgen] pub fn get(target: &JsValue, property_key: &JsValue) -> JsValue { let result = js::Reflect::get(target, property_key); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -295,7 +295,7 @@ fn get() { assert.equal(wasm.get(array, 3), 4); - assert.equal(wasm.get("", 3), "TypeError"); + assert.equal(wasm.get("", 3), "TypeError: Reflect.get called on non-object"); } "#, ) @@ -317,11 +317,11 @@ fn get_own_property_descriptor() { #[wasm_bindgen] pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> JsValue { let result = js::Reflect::get_own_property_descriptor(target, property_key); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -338,7 +338,7 @@ fn get_own_property_descriptor() { assert.equal(wasm.get_own_property_descriptor(object, "property").value, 42); assert.equal(wasm.get_own_property_descriptor(object, "property1"), undefined); - assert.equal(wasm.get_own_property_descriptor("", "property1"), "TypeError"); + assert.equal(wasm.get_own_property_descriptor("", "property1"), "TypeError: Reflect.getOwnPropertyDescriptor called on non-object"); } "#, ) @@ -360,11 +360,11 @@ fn get_prototype_of() { #[wasm_bindgen] pub fn get_prototype_of(target: &JsValue) -> JsValue { let result = js::Reflect::get_prototype_of(target); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -382,7 +382,7 @@ fn get_prototype_of() { assert.equal(wasm.get_prototype_of(object), Object.prototype); assert.equal(wasm.get_prototype_of(array), Array.prototype); - assert.equal(wasm.get_prototype_of(""), "TypeError"); + assert.equal(wasm.get_prototype_of(""), "TypeError: Reflect.getPrototypeOf called on non-object"); } "#, ) @@ -444,11 +444,11 @@ fn is_extensible() { #[wasm_bindgen] pub fn is_extensible(target: &js::Object) -> JsValue { let result = js::Reflect::is_extensible(target); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -472,7 +472,7 @@ fn is_extensible() { const object2 = Object.seal({}); assert.equal(wasm.is_extensible(object2), false); - assert.equal(wasm.is_extensible(""), "TypeError"); + assert.equal(wasm.is_extensible(""), "TypeError: Reflect.isExtensible called on non-object"); } "#, ) @@ -494,11 +494,11 @@ fn own_keys() { #[wasm_bindgen] pub fn own_keys(target: &js::Object) -> JsValue { let result = js::Reflect::own_keys(target); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -517,7 +517,7 @@ fn own_keys() { assert.equal(wasm.own_keys(object)[0], "property"); assert.equal(wasm.own_keys(array)[0], "length"); - assert.equal(wasm.own_keys(""), "TypeError"); + assert.equal(wasm.own_keys(""), "TypeError: Reflect.ownKeys called on non-object"); } "#, ) @@ -539,11 +539,10 @@ fn prevent_extensions() { #[wasm_bindgen] pub fn prevent_extensions(target: &js::Object) -> JsValue { let result = js::Reflect::prevent_extensions(target); - let result = match result { + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -559,6 +558,7 @@ fn prevent_extensions() { wasm.prevent_extensions(object1); assert.equal(Reflect.isExtensible(object1), false); + assert.equal(wasm.prevent_extensions(""), "TypeError: Reflect.preventExtensions called on non-object"); } "#, ) @@ -580,11 +580,10 @@ fn set() { #[wasm_bindgen] pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> JsValue { let result = js::Reflect::set(target, property_key, value); - let result = match result { + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -602,7 +601,7 @@ fn set() { assert.equal(Reflect.get(object, "key"), "value"); assert.equal(array[0], 100); - assert.equal(wasm.set("", "key", "value"), "TypeError"); + assert.equal(wasm.set("", "key", "value"), "TypeError: Reflect.set called on non-object"); } "#, ) @@ -624,11 +623,10 @@ fn set_with_receiver() { #[wasm_bindgen] pub fn set_with_receiver(target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue) -> JsValue { let result = js::Reflect::set_with_receiver(target, property_key, value, receiver); - let result = match result { + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -646,7 +644,7 @@ fn set_with_receiver() { assert.equal(Reflect.get(object, "key"), "value"); assert.equal(array[0], 100); - assert.equal(wasm.set_with_receiver("", "key", "value", ""), "TypeError"); + assert.equal(wasm.set_with_receiver("", "key", "value", ""), "TypeError: Reflect.set called on non-object"); } "#, ) @@ -668,11 +666,11 @@ fn set_prototype_of() { #[wasm_bindgen] pub fn set_prototype_of(target: &JsValue, prototype: &JsValue) -> JsValue { let result = js::Reflect::set_prototype_of(target, prototype); - let result = match result { + + match result { Ok(val) => val, - Err(_err) => "TypeError".into() - }; - result + Err(_err) => _err + } } "#, ) @@ -689,7 +687,7 @@ fn set_prototype_of() { assert.equal(wasm.set_prototype_of(object, null), true); assert.equal(Object.getPrototypeOf(object), null); - assert.equal(wasm.set_prototype_of("", Object.prototype), "TypeError"); + assert.equal(wasm.set_prototype_of("", Object.prototype), "TypeError: Reflect.setPrototypeOf called on non-object"); } "#, ) From 7790b34c076cad4ee8fa51fbb864c79be9a8e9e0 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Wed, 4 Jul 2018 16:10:17 +0200 Subject: [PATCH 17/19] fix: simplify signatures to avoid Result usage --- src/js.rs | 52 ++++++------- tests/all/js_globals/Reflect.rs | 125 ++++++-------------------------- 2 files changed, 49 insertions(+), 128 deletions(-) diff --git a/src/js.rs b/src/js.rs index 34f32443..77ba922e 100644 --- a/src/js.rs +++ b/src/js.rs @@ -986,18 +986,18 @@ extern "C" { /// The static Reflect.apply() method calls a target function with arguments as specified. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/apply - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn apply(target: &Function, this_argument: &JsValue, arguments_list: &Array) -> Result; + #[wasm_bindgen(static_method_of = Reflect)] + pub fn apply(target: &Function, this_argument: &JsValue, arguments_list: &Array) -> JsValue; /// The static Reflect.construct() method acts like the new operator, but as a function. /// It is equivalent to calling new target(...args). It gives also the added option to /// specify a different prototype. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/construct - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn construct(target: &Function, arguments_list: &Array) -> Result; - #[wasm_bindgen(static_method_of = Reflect, js_name = construct, catch)] - pub fn construct_with_new_target(target: &Function, arguments_list: &Array, new_target: &Function) -> Result; + #[wasm_bindgen(static_method_of = Reflect)] + pub fn construct(target: &Function, arguments_list: &Array) -> JsValue; + #[wasm_bindgen(static_method_of = Reflect, js_name = construct)] + pub fn construct_with_new_target(target: &Function, arguments_list: &Array, new_target: &Function) -> JsValue; /// The static Reflect.defineProperty() method is like Object.defineProperty() /// but returns a Boolean. @@ -1010,23 +1010,23 @@ extern "C" { /// It is like the delete operator as a function. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/deleteProperty - #[wasm_bindgen(static_method_of = Reflect, js_name = deleteProperty, catch)] - pub fn delete_property(target: &JsValue, key: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = deleteProperty)] + pub fn delete_property(target: &Object, key: &JsValue) -> bool; /// The static Reflect.get() method works like getting a property from /// an object (target[propertyKey]) as a function. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/get - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn get(target: &JsValue, key: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect)] + pub fn get(target: &Object, key: &JsValue) -> JsValue; /// The static Reflect.getOwnPropertyDescriptor() method is similar to /// Object.getOwnPropertyDescriptor(). It returns a property descriptor /// of the given property if it exists on the object, undefined otherwise. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getOwnPropertyDescriptor - #[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor, catch)] - pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = getOwnPropertyDescriptor)] + pub fn get_own_property_descriptor(target: &Object, property_key: &JsValue) -> JsValue; /// The static Reflect.getPrototypeOf() method is almost the same /// method as Object.getPrototypeOf(). It returns the prototype @@ -1034,8 +1034,8 @@ extern "C" { /// the specified object. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/getPrototypeOf - #[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf, catch)] - pub fn get_prototype_of(target: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = getPrototypeOf)] + pub fn get_prototype_of(target: &Object) -> Object; /// The static Reflect.has() method works like the in operator as a function. /// @@ -1048,15 +1048,15 @@ extern "C" { /// Object.isExtensible(), but with some differences. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/isExtensible - #[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible, catch)] - pub fn is_extensible(target: &Object) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = isExtensible)] + pub fn is_extensible(target: &Object) -> bool; /// The static Reflect.ownKeys() method returns an array of the /// target object's own property keys. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/ownKeys - #[wasm_bindgen(static_method_of = Reflect, js_name = ownKeys, catch)] - pub fn own_keys(target: &Object) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = ownKeys)] + pub fn own_keys(target: &Object) -> Array; /// The static Reflect.preventExtensions() method prevents new /// properties from ever being added to an object (i.e. prevents @@ -1064,17 +1064,17 @@ extern "C" { /// Object.preventExtensions(), but with some differences. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/preventExtensions - #[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions, catch)] - pub fn prevent_extensions(target: &Object) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = preventExtensions)] + pub fn prevent_extensions(target: &Object) -> bool; /// The static Reflect.set() method works like setting a /// property on an object. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/set - #[wasm_bindgen(static_method_of = Reflect, catch)] - pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> Result; - #[wasm_bindgen(static_method_of = Reflect, js_name = set, catch)] - pub fn set_with_receiver(target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect)] + pub fn set(target: &Object, property_key: &JsValue, value: &JsValue) -> bool; + #[wasm_bindgen(static_method_of = Reflect, js_name = set)] + pub fn set_with_receiver(target: &Object, property_key: &JsValue, value: &JsValue, receiver: &Object) -> bool; /// The static Reflect.setPrototypeOf() method is the same /// method as Object.setPrototypeOf(). It sets the prototype @@ -1082,8 +1082,8 @@ extern "C" { /// object to another object or to null. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/setPrototypeOf - #[wasm_bindgen(static_method_of = Reflect, js_name = setPrototypeOf, catch)] - pub fn set_prototype_of(target: &JsValue, prototype: &JsValue) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = setPrototypeOf)] + pub fn set_prototype_of(target: &Object, prototype: &JsValue) -> bool; } // Set diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index 7877e9db..e3903466 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -16,12 +16,7 @@ fn apply() { #[wasm_bindgen] pub fn apply(target: &js::Function, this_argument: &JsValue, arguments_list: &js::Array) -> JsValue { - let result = js::Reflect::apply(target, this_argument, arguments_list); - - match result { - Ok(val) => val, - Err(_err) => _err - } + js::Reflect::apply(target, this_argument, arguments_list) } "#, ) @@ -33,7 +28,6 @@ fn apply() { export function test() { assert.equal(wasm.apply("".charAt, "ponies", [3]), "i"); - assert.equal(wasm.apply("", "ponies", [3]), "TypeError: Function.prototype.apply was called on , which is a string and not a function"); } "#, ) @@ -54,12 +48,7 @@ fn construct() { #[wasm_bindgen] pub fn construct(target: &js::Function, arguments_list: &js::Array) -> JsValue { - let result = js::Reflect::construct(target, arguments_list); - - match result { - Ok(val) => val, - Err(_err) => _err - } + js::Reflect::construct(target, arguments_list) } "#, ) @@ -88,7 +77,6 @@ fn construct() { const args = [10, 10]; assert.equal(wasm.construct(Rectangle, args).x, 10); - assert.equal(wasm.construct("", args), "TypeError: is not a constructor"); } "#, ) @@ -109,12 +97,7 @@ fn construct_with_new_target() { #[wasm_bindgen] pub fn construct_with_new_target(target: &js::Function, arguments_list: &js::Array, new_target: &js::Function) -> JsValue { - let result = js::Reflect::construct_with_new_target(target, arguments_list, new_target); - - match result { - Ok(val) => val, - Err(_err) => _err - } + js::Reflect::construct_with_new_target(target, arguments_list, new_target) } "#, ) @@ -158,7 +141,6 @@ fn construct_with_new_target() { const args = [10, 10]; assert.equal(wasm.construct_with_new_target(Rectangle, args, Rectangle2).x, 10); - assert.equal(wasm.construct_with_new_target(Rectangle, args, ""), "TypeError: is not a constructor"); } "#, ) @@ -218,13 +200,8 @@ fn delete_property() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn delete_property(target: &JsValue, property_key: &JsValue) -> JsValue { - let result = js::Reflect::delete_property(target, property_key); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn delete_property(target: &js::Object, property_key: &JsValue) -> bool { + js::Reflect::delete_property(target, property_key) } "#, ) @@ -247,8 +224,6 @@ fn delete_property() { wasm.delete_property(array, 3); assert.equal(array[3], undefined); - - assert.equal(wasm.delete_property("", 3), "TypeError: Reflect.deleteProperty called on non-object"); } "#, ) @@ -268,13 +243,8 @@ fn get() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn get(target: &JsValue, property_key: &JsValue) -> JsValue { - let result = js::Reflect::get(target, property_key); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn get(target: &js::Object, property_key: &JsValue) -> JsValue { + js::Reflect::get(target, property_key) } "#, ) @@ -294,8 +264,6 @@ fn get() { const array = [1, 2, 3, 4, 5]; assert.equal(wasm.get(array, 3), 4); - - assert.equal(wasm.get("", 3), "TypeError: Reflect.get called on non-object"); } "#, ) @@ -315,13 +283,8 @@ fn get_own_property_descriptor() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn get_own_property_descriptor(target: &JsValue, property_key: &JsValue) -> JsValue { - let result = js::Reflect::get_own_property_descriptor(target, property_key); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn get_own_property_descriptor(target: &js::Object, property_key: &JsValue) -> JsValue { + js::Reflect::get_own_property_descriptor(target, property_key) } "#, ) @@ -338,7 +301,6 @@ fn get_own_property_descriptor() { assert.equal(wasm.get_own_property_descriptor(object, "property").value, 42); assert.equal(wasm.get_own_property_descriptor(object, "property1"), undefined); - assert.equal(wasm.get_own_property_descriptor("", "property1"), "TypeError: Reflect.getOwnPropertyDescriptor called on non-object"); } "#, ) @@ -358,13 +320,8 @@ fn get_prototype_of() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn get_prototype_of(target: &JsValue) -> JsValue { - let result = js::Reflect::get_prototype_of(target); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn get_prototype_of(target: &js::Object) -> js::Object { + js::Reflect::get_prototype_of(target) } "#, ) @@ -382,7 +339,6 @@ fn get_prototype_of() { assert.equal(wasm.get_prototype_of(object), Object.prototype); assert.equal(wasm.get_prototype_of(array), Array.prototype); - assert.equal(wasm.get_prototype_of(""), "TypeError: Reflect.getPrototypeOf called on non-object"); } "#, ) @@ -442,13 +398,8 @@ fn is_extensible() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn is_extensible(target: &js::Object) -> JsValue { - let result = js::Reflect::is_extensible(target); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn is_extensible(target: &js::Object) -> bool { + js::Reflect::is_extensible(target) } "#, ) @@ -472,7 +423,6 @@ fn is_extensible() { const object2 = Object.seal({}); assert.equal(wasm.is_extensible(object2), false); - assert.equal(wasm.is_extensible(""), "TypeError: Reflect.isExtensible called on non-object"); } "#, ) @@ -492,13 +442,8 @@ fn own_keys() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn own_keys(target: &js::Object) -> JsValue { - let result = js::Reflect::own_keys(target); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn own_keys(target: &js::Object) -> js::Array { + js::Reflect::own_keys(target) } "#, ) @@ -516,8 +461,6 @@ fn own_keys() { assert.equal(wasm.own_keys(object)[0], "property"); assert.equal(wasm.own_keys(array)[0], "length"); - - assert.equal(wasm.own_keys(""), "TypeError: Reflect.ownKeys called on non-object"); } "#, ) @@ -537,12 +480,8 @@ fn prevent_extensions() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn prevent_extensions(target: &js::Object) -> JsValue { - let result = js::Reflect::prevent_extensions(target); - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn prevent_extensions(target: &js::Object) -> bool { + js::Reflect::prevent_extensions(target) } "#, ) @@ -558,7 +497,6 @@ fn prevent_extensions() { wasm.prevent_extensions(object1); assert.equal(Reflect.isExtensible(object1), false); - assert.equal(wasm.prevent_extensions(""), "TypeError: Reflect.preventExtensions called on non-object"); } "#, ) @@ -578,12 +516,8 @@ fn set() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn set(target: &JsValue, property_key: &JsValue, value: &JsValue) -> JsValue { - let result = js::Reflect::set(target, property_key, value); - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn set(target: &js::Object, property_key: &JsValue, value: &JsValue) -> bool { + js::Reflect::set(target, property_key, value) } "#, ) @@ -601,7 +535,6 @@ fn set() { assert.equal(Reflect.get(object, "key"), "value"); assert.equal(array[0], 100); - assert.equal(wasm.set("", "key", "value"), "TypeError: Reflect.set called on non-object"); } "#, ) @@ -621,12 +554,8 @@ fn set_with_receiver() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn set_with_receiver(target: &JsValue, property_key: &JsValue, value: &JsValue, receiver: &JsValue) -> JsValue { - let result = js::Reflect::set_with_receiver(target, property_key, value, receiver); - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn set_with_receiver(target: &js::Object, property_key: &JsValue, value: &JsValue, receiver: &js::Object) -> bool { + js::Reflect::set_with_receiver(target, property_key, value, receiver) } "#, ) @@ -644,7 +573,6 @@ fn set_with_receiver() { assert.equal(Reflect.get(object, "key"), "value"); assert.equal(array[0], 100); - assert.equal(wasm.set_with_receiver("", "key", "value", ""), "TypeError: Reflect.set called on non-object"); } "#, ) @@ -664,13 +592,8 @@ fn set_prototype_of() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn set_prototype_of(target: &JsValue, prototype: &JsValue) -> JsValue { - let result = js::Reflect::set_prototype_of(target, prototype); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn set_prototype_of(target: &js::Object, prototype: &JsValue) -> bool { + js::Reflect::set_prototype_of(target, prototype) } "#, ) @@ -686,8 +609,6 @@ fn set_prototype_of() { assert.equal(Object.getPrototypeOf(object), Object.prototype); assert.equal(wasm.set_prototype_of(object, null), true); assert.equal(Object.getPrototypeOf(object), null); - - assert.equal(wasm.set_prototype_of("", Object.prototype), "TypeError: Reflect.setPrototypeOf called on non-object"); } "#, ) From 8dd8475000f3cc32e590e6bd558aa31a71d4324b Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Thu, 5 Jul 2018 08:33:22 +0200 Subject: [PATCH 18/19] fix: Reflec.defineProperty no longer returns Result --- src/js.rs | 4 ++-- tests/all/js_globals/Reflect.rs | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/js.rs b/src/js.rs index 77ba922e..1de3d662 100644 --- a/src/js.rs +++ b/src/js.rs @@ -1003,8 +1003,8 @@ extern "C" { /// but returns a Boolean. /// /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Reflect/defineProperty - #[wasm_bindgen(static_method_of = Reflect, js_name = defineProperty, catch)] - pub fn define_property(target: &Object, property_key: &JsValue, attributes: &Object) -> Result; + #[wasm_bindgen(static_method_of = Reflect, js_name = defineProperty)] + pub fn define_property(target: &Object, property_key: &JsValue, attributes: &Object) -> bool; /// The static Reflect.deleteProperty() method allows to delete properties. /// It is like the delete operator as a function. diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index e3903466..c6cf3b09 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -160,13 +160,8 @@ fn define_property() { use wasm_bindgen::js; #[wasm_bindgen] - pub fn define_property(target: &js::Object, property_key: &JsValue, attributes: &js::Object) -> JsValue { - let result = js::Reflect::define_property(target, property_key, attributes); - - match result { - Ok(val) => val, - Err(_err) => _err - } + pub fn define_property(target: &js::Object, property_key: &JsValue, attributes: &js::Object) -> bool { + js::Reflect::define_property(target, property_key, attributes) } "#, ) @@ -180,7 +175,6 @@ fn define_property() { const object = {}; assert.equal(wasm.define_property(object, "key", { value: 42}), true) - assert.equal(wasm.define_property("", "key", { value: 42 }), "TypeError: Reflect.defineProperty called on non-object"); } "#, ) From 2022b4441604411c31a480939906798240f6da54 Mon Sep 17 00:00:00 2001 From: Jannik Keye Date: Fri, 6 Jul 2018 09:41:08 +0200 Subject: [PATCH 19/19] fix: convert tests to plain js --- tests/all/js_globals/Reflect.rs | 61 ++++++++++++++------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/tests/all/js_globals/Reflect.rs b/tests/all/js_globals/Reflect.rs index c6cf3b09..a95572d5 100644 --- a/tests/all/js_globals/Reflect.rs +++ b/tests/all/js_globals/Reflect.rs @@ -21,7 +21,7 @@ fn apply() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -53,22 +53,19 @@ fn construct() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; export function test() { class Rectangle { - public x: number; - public y: number; - - constructor(x: number, y: number){ + constructor(x, y){ this.x = x, this.y = y } - static eq(x: number, y: number) { + static eq(x, y) { return x === y; } @@ -102,37 +99,31 @@ fn construct_with_new_target() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; export function test() { class Rectangle { - public x: number; - public y: number; - - constructor(x: number, y: number){ + constructor(x, y){ this.x = x, this.y = y } - static eq(x: number, y: number) { + static eq(x, y) { return x === y; } } class Rectangle2 { - public x: number; - public y: number; - - constructor(x: number, y: number){ + constructor(x, y){ this.x = x, this.y = y } - static eq(x: number, y: number) { + static eq(x, y) { return x === y; } @@ -166,7 +157,7 @@ fn define_property() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -200,7 +191,7 @@ fn delete_property() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -243,7 +234,7 @@ fn get() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -283,7 +274,7 @@ fn get_own_property_descriptor() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -320,7 +311,7 @@ fn get_prototype_of() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -329,7 +320,7 @@ fn get_prototype_of() { const object = { property: 42 }; - const array: number[] = [1, 2, 3]; + const array = [1, 2, 3]; assert.equal(wasm.get_prototype_of(object), Object.prototype); assert.equal(wasm.get_prototype_of(array), Array.prototype); @@ -358,7 +349,7 @@ fn has() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -367,7 +358,7 @@ fn has() { const object = { property: 42 }; - const array: number[] = [1, 2, 3, 4] + const array = [1, 2, 3, 4] assert.equal(wasm.has(object, "property"), true); assert.equal(wasm.has(object, "foo"), false); @@ -398,7 +389,7 @@ fn is_extensible() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -442,7 +433,7 @@ fn own_keys() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -451,7 +442,7 @@ fn own_keys() { const object = { property: 42 }; - const array: number[] = []; + const array = []; assert.equal(wasm.own_keys(object)[0], "property"); assert.equal(wasm.own_keys(array)[0], "length"); @@ -480,7 +471,7 @@ fn prevent_extensions() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; @@ -516,14 +507,14 @@ fn set() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; export function test() { const object = {}; - const array: number[] = [1, 2, 3, 4]; + const array = [1, 2, 3, 4]; assert.equal(wasm.set(object, "key", "value"), true); assert.equal(wasm.set(array, 0, 100), true); @@ -554,14 +545,14 @@ fn set_with_receiver() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out"; export function test() { const object = {}; - const array: number[] = [1, 2, 3, 4]; + const array = [1, 2, 3, 4]; assert.equal(wasm.set_with_receiver({}, "key", "value", object), true); assert.equal(wasm.set_with_receiver([], 0, 100, array), true); @@ -592,7 +583,7 @@ fn set_prototype_of() { "#, ) .file( - "test.ts", + "test.js", r#" import * as assert from "assert"; import * as wasm from "./out";