summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPale Moon <git-repo@palemoon.org>2018-01-17 11:11:06 +0100
committerPale Moon <git-repo@palemoon.org>2018-01-17 16:40:18 +0100
commitc69708c68fd13eb4c47020ccf366489db7b01c65 (patch)
tree81179ae70fbc6612ea0e3218dea5e2c7c065ecb0
parent89848140a721cde16c96465b4f3b70c75d5cbb9a (diff)
downloadpalemoon-c69708c68fd13eb4c47020ccf366489db7b01c65.tar.gz
Implement ES6 22.1.3.31 Array.prototype[@@unscopables]
This resolves #1587 and is an essential part of Unscopables.
-rw-r--r--js/src/jsarray.cpp30
-rw-r--r--js/src/jsarray.h3
-rw-r--r--js/src/vm/CommonPropertyNames.h6
3 files changed, 35 insertions, 4 deletions
diff --git a/js/src/jsarray.cpp b/js/src/jsarray.cpp
index a43afc437..7b33cd905 100644
--- a/js/src/jsarray.cpp
+++ b/js/src/jsarray.cpp
@@ -3291,6 +3291,32 @@ CreateArrayPrototype(JSContext* cx, JSProtoKey key)
return arrayProto;
}
+static bool
+array_proto_finish(JSContext* cx, JS::HandleObject ctor, JS::HandleObject proto)
+{
+ // Add Array.prototype[@@unscopables]. ECMA-262 6.0 22.1.3.31.
+ RootedObject unscopables(cx, NewObjectWithGivenProto<PlainObject>(cx, NullPtr(), NullPtr(), TenuredObject));
+ if (!unscopables)
+ return false;
+
+ RootedValue value(cx, BooleanValue(true));
+ if (!DefineProperty(cx, unscopables, cx->names().copyWithin, value) ||
+ !DefineProperty(cx, unscopables, cx->names().entries, value) ||
+ !DefineProperty(cx, unscopables, cx->names().fill, value) ||
+ !DefineProperty(cx, unscopables, cx->names().find, value) ||
+ !DefineProperty(cx, unscopables, cx->names().findIndex, value) ||
+ !DefineProperty(cx, unscopables, cx->names().includes, value) ||
+ !DefineProperty(cx, unscopables, cx->names().keys, value) ||
+ !DefineProperty(cx, unscopables, cx->names().values, value))
+ {
+ return false;
+ }
+
+ RootedId id(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().get(JS::SymbolCode::unscopables)));
+ value.setObject(*unscopables);
+ return DefineProperty(cx, proto, id, value, nullptr, nullptr, JSPROP_READONLY);
+}
+
const Class ArrayObject::class_ = {
"Array",
JSCLASS_HAS_CACHED_PROTO(JSProto_Array),
@@ -3310,7 +3336,9 @@ const Class ArrayObject::class_ = {
GenericCreateConstructor<js_Array, 1, JSFunction::FinalizeKind>,
CreateArrayPrototype,
array_static_methods,
- array_methods
+ array_methods,
+ nullptr,
+ array_proto_finish
}
};
diff --git a/js/src/jsarray.h b/js/src/jsarray.h
index 4265f4386..4e471df77 100644
--- a/js/src/jsarray.h
+++ b/js/src/jsarray.h
@@ -33,9 +33,6 @@ js_IdIsIndex(jsid id, uint32_t* indexp)
return js::StringIsArrayIndex(JSID_TO_ATOM(id), indexp);
}
-extern JSObject*
-js_InitArrayClass(JSContext* cx, js::HandleObject obj);
-
extern bool
js_InitContextBusyArrayTable(JSContext* cx);
diff --git a/js/src/vm/CommonPropertyNames.h b/js/src/vm/CommonPropertyNames.h
index 87b9bc6a6..87b9ffdc0 100644
--- a/js/src/vm/CommonPropertyNames.h
+++ b/js/src/vm/CommonPropertyNames.h
@@ -44,6 +44,7 @@
macro(construct, construct, "construct") \
macro(constructor, constructor, "constructor") \
macro(ConvertAndCopyTo, ConvertAndCopyTo, "ConvertAndCopyTo") \
+ macro(copyWithin, copyWithin, "copyWithin") \
macro(count, count, "count") \
macro(currency, currency, "currency") \
macro(currencyDisplay, currencyDisplay, "currencyDisplay") \
@@ -67,6 +68,7 @@
macro(emptyRegExp, emptyRegExp, "(?:)") \
macro(encodeURI, encodeURI, "encodeURI") \
macro(encodeURIComponent, encodeURIComponent, "encodeURIComponent") \
+ macro(entries, entries, "entries") \
macro(enumerable, enumerable, "enumerable") \
macro(enumerate, enumerate, "enumerate") \
macro(escape, escape, "escape") \
@@ -75,6 +77,9 @@
macro(fieldOffsets, fieldOffsets, "fieldOffsets") \
macro(fieldTypes, fieldTypes, "fieldTypes") \
macro(fileName, fileName, "fileName") \
+ macro(fill, fill, "fill") \
+ macro(find, find, "find") \
+ macro(findIndex, findIndex, "findIndex") \
macro(fix, fix, "fix") \
macro(float32, float32, "float32") \
macro(float32x4, float32x4, "float32x4") \
@@ -97,6 +102,7 @@
macro(hasOwnProperty, hasOwnProperty, "hasOwnProperty") \
macro(ignoreCase, ignoreCase, "ignoreCase") \
macro(ignorePunctuation, ignorePunctuation, "ignorePunctuation") \
+ macro(includes, includes, "includes") \
macro(index, index, "index") \
macro(InitializeCollator, InitializeCollator, "InitializeCollator") \
macro(InitializeDateTimeFormat, InitializeDateTimeFormat, "InitializeDateTimeFormat") \