Commit 57ebbbd
Spec alignment create method property (#5013)
This PR aligns Boa more closely with the ECMAScript specification by
implementing missing abstract operations and centralizing them in
[operations.rs](file:///home/mayank/boa/core/engine/src/object/operations.rs).
#### **1. Implement `CreateMethodProperty`
([§7.3.5](https://tc39.es/ecma262/#sec-createmethodproperty))**
Added the
[create_method_property](file:///home/mayank/boa/core/engine/src/object/operations.rs#180-208)
helper to
[core/engine/src/object/operations.rs](file:///home/mayank/boa/core/engine/src/object/operations.rs).
**Before:**
```rust
// core/engine/src/object/operations.rs
// todo: CreateMethodProperty
```
**After:**
```rust
pub(crate) fn create_method_property<K, V>(
&self,
key: K,
value: V,
context: &mut InternalMethodPropertyContext<'_>,
) -> JsResult<bool>
where
K: Into<PropertyKey>,
V: Into<JsValue>,
{
let new_desc = PropertyDescriptor::builder()
.value(value)
.writable(true)
.enumerable(false)
.configurable(true);
self.__define_own_property__(&key.into(), new_desc.into(), context)
}
```
#### **2. Move
[CopyDataProperties](file:///home/mayank/boa/core/engine/src/vm/opcode/copy/mod.rs#10-11)
([§7.3.26](https://tc39.es/ecma262/#sec-copydataproperties))**
Moved the implementation from
[jsobject.rs](file:///home/mayank/boa/core/engine/src/object/jsobject.rs)
to
[operations.rs](file:///home/mayank/boa/core/engine/src/object/operations.rs)
to center abstract operations as suggested by internal `todo` comments.
**Before:**
-
[jsobject.rs](file:///home/mayank/boa/core/engine/src/object/jsobject.rs):
Contained the implementation of
[copy_data_properties](file:///home/mayank/boa/core/engine/src/object/operations.rs#872-940).
-
[operations.rs](file:///home/mayank/boa/core/engine/src/object/operations.rs):
Contained `// todo: CopyDataProperties`.
**After:**
-
[jsobject.rs](file:///home/mayank/boa/core/engine/src/object/jsobject.rs):
Implementation removed.
-
[operations.rs](file:///home/mayank/boa/core/engine/src/object/operations.rs):
```rust
pub fn copy_data_properties<K>(
&self,
source: &JsValue,
excluded_keys: Vec<K>,
context: &mut Context,
) -> JsResult<()> {
// ... (Implementation moved here)
}
```
### **Tests**
- Verified with `cargo check -p boa_engine`.
- Confirmed formatting with `cargo fmt`.
---------
Co-authored-by: Your Name <test@example.com>
Co-authored-by: Prabal Patra <163229512+alienx5499@users.noreply.github.com>
Co-authored-by: ash <ashddev@proton.me>1 parent 1848e23 commit 57ebbbd
File tree
3 files changed
+113
-98
lines changed- core/engine/src
- object
- vm/opcode/define/class
3 files changed
+113
-98
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
| 7 | + | |
10 | 8 | | |
11 | 9 | | |
12 | 10 | | |
| |||
768 | 766 | | |
769 | 767 | | |
770 | 768 | | |
771 | | - | |
772 | | - | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
777 | | - | |
778 | | - | |
779 | | - | |
780 | | - | |
781 | | - | |
782 | | - | |
783 | | - | |
784 | | - | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
794 | | - | |
795 | | - | |
796 | | - | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
808 | | - | |
809 | | - | |
810 | | - | |
811 | | - | |
812 | | - | |
813 | | - | |
814 | | - | |
815 | | - | |
816 | | - | |
817 | | - | |
818 | | - | |
819 | | - | |
820 | | - | |
821 | | - | |
822 | | - | |
823 | | - | |
824 | | - | |
825 | | - | |
826 | | - | |
827 | | - | |
828 | | - | |
829 | | - | |
830 | | - | |
831 | | - | |
832 | | - | |
833 | | - | |
834 | | - | |
835 | | - | |
836 | | - | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | 769 | | |
841 | 770 | | |
842 | 771 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
181 | 215 | | |
182 | 216 | | |
183 | 217 | | |
| |||
842 | 876 | | |
843 | 877 | | |
844 | 878 | | |
845 | | - | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
846 | 947 | | |
847 | 948 | | |
848 | 949 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
50 | 45 | | |
51 | 46 | | |
52 | 47 | | |
| |||
92 | 87 | | |
93 | 88 | | |
94 | 89 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
103 | 93 | | |
104 | 94 | | |
105 | 95 | | |
| |||
194 | 184 | | |
195 | 185 | | |
196 | 186 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
205 | 190 | | |
206 | 191 | | |
207 | 192 | | |
| |||
0 commit comments