summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2023-05-29 22:47:26 +0200
committerMoonchild <moonchild@palemoon.org>2023-05-29 22:47:26 +0200
commit6e35a8566e2a91242b54e2b21256317e00a934bb (patch)
treed35d25992e39f6a483b7cec35fe09689334f1cbb /js
parent281a8854d068f1dbe2d4145ffd0664ac345af00d (diff)
downloaduxp-6e35a8566e2a91242b54e2b21256317e00a934bb.tar.gz
Issue #2256 - Implement Object.hasOwn(object, property)
This is a convenience access function to hasOwnProperty. Trivial, self-hosted implementation providing the interface to the already existing hasOwnProperty cpp function with additional toObject for spec compliance. Resolves #2256
Diffstat (limited to 'js')
-rw-r--r--js/src/builtin/Object.cpp1
-rw-r--r--js/src/builtin/Object.js9
2 files changed, 10 insertions, 0 deletions
diff --git a/js/src/builtin/Object.cpp b/js/src/builtin/Object.cpp
index 70a21079c0..5221afb617 100644
--- a/js/src/builtin/Object.cpp
+++ b/js/src/builtin/Object.cpp
@@ -1240,6 +1240,7 @@ static const JSFunctionSpec object_static_methods[] = {
JS_FN("seal", obj_seal, 1, 0),
JS_FN("isSealed", obj_isSealed, 1, 0),
JS_SELF_HOSTED_FN("fromEntries", "ObjectFromEntries", 1, 0),
+ JS_SELF_HOSTED_FN("hasOwn", "ObjectHasOwn", 2, 0),
JS_FS_END
};
diff --git a/js/src/builtin/Object.js b/js/src/builtin/Object.js
index c4739037e3..59d4807317 100644
--- a/js/src/builtin/Object.js
+++ b/js/src/builtin/Object.js
@@ -220,3 +220,12 @@ function ObjectFromEntries(iter) {
return obj;
}
+
+// Proposal https://github.com/tc39/proposal-accessible-object-hasownproperty
+// Object.hasOwn (Object, Property)
+function ObjectHasOwn(O, P) {
+ // Step 1.
+ var obj = ToObject(O);
+ // Step 2-3.
+ return callFunction(std_Object_hasOwnProperty, obj, P);
+}