Commit 58d623f2 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Stage ES6 promises and weak collections

Split collections flag into weak and non-weak.

R=mstarzinger@chromium.org
BUG=

Review URL: https://codereview.chromium.org/201593004

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20019 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d7844ec8
......@@ -1350,16 +1350,19 @@ void Genesis::InitializeExperimentalGlobal() {
}
if (FLAG_harmony_collections) {
{ // -- S e t
InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize,
{ // -- M a p
InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize,
isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true);
}
{ // -- M a p
InstallFunction(global, "Map", JS_MAP_TYPE, JSMap::kSize,
{ // -- S e t
InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize,
isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true);
}
}
if (FLAG_harmony_weak_collections) {
{ // -- W e a k M a p
InstallFunction(global, "WeakMap", JS_WEAK_MAP_TYPE, JSWeakMap::kSize,
isolate()->initial_object_prototype(),
......@@ -2050,6 +2053,7 @@ bool Genesis::InstallExperimentalNatives() {
INSTALL_EXPERIMENTAL_NATIVE(i, symbols, "symbol.js")
INSTALL_EXPERIMENTAL_NATIVE(i, proxies, "proxy.js")
INSTALL_EXPERIMENTAL_NATIVE(i, collections, "collection.js")
INSTALL_EXPERIMENTAL_NATIVE(i, weak_collections, "weak_collection.js")
INSTALL_EXPERIMENTAL_NATIVE(i, promises, "promise.js")
INSTALL_EXPERIMENTAL_NATIVE(i, generators, "generator.js")
INSTALL_EXPERIMENTAL_NATIVE(i, iteration, "array-iterator.js")
......
......@@ -33,8 +33,6 @@
var $Set = global.Set;
var $Map = global.Map;
var $WeakMap = global.WeakMap;
var $WeakSet = global.WeakSet;
// Global sentinel to be used instead of undefined keys, which are not
// supported internally but required for Harmony sets and maps.
......@@ -230,174 +228,3 @@ function SetUpMap() {
}
SetUpMap();
// -------------------------------------------------------------------
// Harmony WeakMap
function WeakMapConstructor() {
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
throw MakeTypeError('constructor_not_function', ['WeakMap']);
}
}
function WeakMapGet(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.get', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionGet(this, key);
}
function WeakMapSet(key, value) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.set', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionSet(this, key, value);
}
function WeakMapHas(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.has', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionHas(this, key);
}
function WeakMapDelete(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.delete', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionDelete(this, key);
}
function WeakMapClear() {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.clear', this]);
}
// Replace the internal table with a new empty table.
%WeakCollectionInitialize(this);
}
// -------------------------------------------------------------------
function SetUpWeakMap() {
%CheckIsBootstrapping();
%SetCode($WeakMap, WeakMapConstructor);
%FunctionSetPrototype($WeakMap, new $Object());
%SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
// Set up the non-enumerable functions on the WeakMap prototype object.
InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
"get", WeakMapGet,
"set", WeakMapSet,
"has", WeakMapHas,
"delete", WeakMapDelete,
"clear", WeakMapClear
));
}
SetUpWeakMap();
// -------------------------------------------------------------------
// Harmony WeakSet
function WeakSetConstructor() {
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
throw MakeTypeError('constructor_not_function', ['WeakSet']);
}
}
function WeakSetAdd(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.add', this]);
}
if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
return %WeakCollectionSet(this, value, true);
}
function WeakSetHas(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.has', this]);
}
if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
return %WeakCollectionHas(this, value);
}
function WeakSetDelete(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.delete', this]);
}
if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
return %WeakCollectionDelete(this, value);
}
function WeakSetClear() {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.clear', this]);
}
// Replace the internal table with a new empty table.
%WeakCollectionInitialize(this);
}
// -------------------------------------------------------------------
function SetUpWeakSet() {
%CheckIsBootstrapping();
%SetCode($WeakSet, WeakSetConstructor);
%FunctionSetPrototype($WeakSet, new $Object());
%SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM);
// Set up the non-enumerable functions on the WeakSet prototype object.
InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array(
"add", WeakSetAdd,
"has", WeakSetHas,
"delete", WeakSetDelete,
"clear", WeakSetClear
));
}
SetUpWeakSet();
......@@ -178,7 +178,9 @@ DEFINE_bool(harmony_symbols, false,
DEFINE_bool(harmony_promises, false, "enable harmony promises")
DEFINE_bool(harmony_proxies, false, "enable harmony proxies")
DEFINE_bool(harmony_collections, false,
"enable harmony collections (sets, maps, and weak maps)")
"enable harmony collections (sets, maps, weak sets, weak maps)")
DEFINE_bool(harmony_weak_collections, false,
"enable only harmony weak collections (weak sets and maps)")
DEFINE_bool(harmony_generators, false, "enable harmony generators")
DEFINE_bool(harmony_iteration, false, "enable harmony iteration (for-of)")
DEFINE_bool(harmony_numeric_literals, false,
......@@ -191,7 +193,6 @@ DEFINE_bool(harmony, false, "enable all harmony features (except typeof)")
DEFINE_implication(harmony, harmony_scoping)
DEFINE_implication(harmony, harmony_modules)
DEFINE_implication(harmony, harmony_symbols)
DEFINE_implication(harmony, harmony_promises)
DEFINE_implication(harmony, harmony_proxies)
DEFINE_implication(harmony, harmony_collections)
DEFINE_implication(harmony, harmony_generators)
......@@ -199,11 +200,14 @@ DEFINE_implication(harmony, harmony_iteration)
DEFINE_implication(harmony, harmony_numeric_literals)
DEFINE_implication(harmony, harmony_strings)
DEFINE_implication(harmony, harmony_arrays)
DEFINE_implication(harmony_promises, harmony_collections)
DEFINE_implication(harmony_collections, harmony_weak_collections)
DEFINE_implication(harmony_promises, harmony_weak_collections)
DEFINE_implication(harmony_modules, harmony_scoping)
DEFINE_implication(harmony, es_staging)
DEFINE_implication(es_staging, harmony_maths)
DEFINE_implication(es_staging, harmony_promises)
DEFINE_implication(es_staging, harmony_weak_collections)
// Flags for experimental implementation features.
DEFINE_bool(packed_arrays, true, "optimizes arrays that have no holes")
......
// Copyright 2012 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"use strict";
// This file relies on the fact that the following declaration has been made
// in runtime.js:
// var $Array = global.Array;
var $WeakMap = global.WeakMap;
var $WeakSet = global.WeakSet;
// -------------------------------------------------------------------
// Harmony WeakMap
function WeakMapConstructor() {
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
throw MakeTypeError('constructor_not_function', ['WeakMap']);
}
}
function WeakMapGet(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.get', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionGet(this, key);
}
function WeakMapSet(key, value) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.set', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionSet(this, key, value);
}
function WeakMapHas(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.has', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionHas(this, key);
}
function WeakMapDelete(key) {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.delete', this]);
}
if (!(IS_SPEC_OBJECT(key) || IS_SYMBOL(key))) {
throw %MakeTypeError('invalid_weakmap_key', [this, key]);
}
return %WeakCollectionDelete(this, key);
}
function WeakMapClear() {
if (!IS_WEAKMAP(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakMap.prototype.clear', this]);
}
// Replace the internal table with a new empty table.
%WeakCollectionInitialize(this);
}
// -------------------------------------------------------------------
function SetUpWeakMap() {
%CheckIsBootstrapping();
%SetCode($WeakMap, WeakMapConstructor);
%FunctionSetPrototype($WeakMap, new $Object());
%SetProperty($WeakMap.prototype, "constructor", $WeakMap, DONT_ENUM);
// Set up the non-enumerable functions on the WeakMap prototype object.
InstallFunctions($WeakMap.prototype, DONT_ENUM, $Array(
"get", WeakMapGet,
"set", WeakMapSet,
"has", WeakMapHas,
"delete", WeakMapDelete,
"clear", WeakMapClear
));
}
SetUpWeakMap();
// -------------------------------------------------------------------
// Harmony WeakSet
function WeakSetConstructor() {
if (%_IsConstructCall()) {
%WeakCollectionInitialize(this);
} else {
throw MakeTypeError('constructor_not_function', ['WeakSet']);
}
}
function WeakSetAdd(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.add', this]);
}
if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
return %WeakCollectionSet(this, value, true);
}
function WeakSetHas(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.has', this]);
}
if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
return %WeakCollectionHas(this, value);
}
function WeakSetDelete(value) {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.delete', this]);
}
if (!(IS_SPEC_OBJECT(value) || IS_SYMBOL(value))) {
throw %MakeTypeError('invalid_weakset_value', [this, value]);
}
return %WeakCollectionDelete(this, value);
}
function WeakSetClear() {
if (!IS_WEAKSET(this)) {
throw MakeTypeError('incompatible_method_receiver',
['WeakSet.prototype.clear', this]);
}
// Replace the internal table with a new empty table.
%WeakCollectionInitialize(this);
}
// -------------------------------------------------------------------
function SetUpWeakSet() {
%CheckIsBootstrapping();
%SetCode($WeakSet, WeakSetConstructor);
%FunctionSetPrototype($WeakSet, new $Object());
%SetProperty($WeakSet.prototype, "constructor", $WeakSet, DONT_ENUM);
// Set up the non-enumerable functions on the WeakSet prototype object.
InstallFunctions($WeakSet.prototype, DONT_ENUM, $Array(
"add", WeakSetAdd,
"has", WeakSetHas,
"delete", WeakSetDelete,
"clear", WeakSetClear
));
}
SetUpWeakSet();
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-collections
// Flags: --harmony-weak-collections
var key = {};
var map = new WeakMap;
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --allow-natives-syntax --harmony-collections
// Flags: --allow-natives-syntax --harmony-weak-collections
var key1 = {};
var key2 = {};
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-collections
// Flags: --harmony-weak-collections
(function test1() {
var wm1 = new WeakMap();
......
This diff is collapsed.
......@@ -25,7 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-observation --harmony-proxies --harmony-collections
// Flags: --harmony-observation --harmony-proxies
// Flags: --harmony-collections --harmony-weak-collections
// Flags: --harmony-symbols --allow-natives-syntax
var allObservers = [];
......
......@@ -25,10 +25,11 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-collections --expose-gc --allow-natives-syntax
// Flags: --harmony-collections --harmony-weak-collections
// Flags: --expose-gc --allow-natives-syntax
// Test valid getter and setter calls on Sets.
// Test valid getter and setter calls on Sets and WeakSets
function TestValidSetCalls(m) {
assertDoesNotThrow(function () { m.add(new Object) });
assertDoesNotThrow(function () { m.has(new Object) });
......@@ -63,7 +64,7 @@ function TestInvalidCalls(m) {
TestInvalidCalls(new WeakMap);
// Test expected behavior for Sets
// Test expected behavior for Sets and WeakSets
function TestSet(set, key) {
assertFalse(set.has(key));
assertSame(undefined, set.add(key));
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-symbols --harmony-collections
// Flags: --harmony-symbols --harmony-collections --harmony-weak-collections
// Flags: --expose-gc --allow-natives-syntax
var symbols = []
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-proxies --harmony-collections
// Flags: --harmony-proxies --harmony-collections --harmony-weak-collections
// Helper.
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony-symbols --harmony-collections
// Flags: --harmony-symbols --harmony-collections --harmony-weak-collections
// Flags: --expose-gc --allow-natives-syntax
var symbols = []
......
......@@ -25,7 +25,7 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --harmony_symbols --harmony-collections
// Flags: --harmony_symbols --harmony-weak-collections
var v0 = new WeakMap;
var v1 = {};
......
......@@ -1066,6 +1066,7 @@
'../../src/symbol.js',
'../../src/proxy.js',
'../../src/collection.js',
'../../src/weak_collection.js',
'../../src/promise.js',
'../../src/generator.js',
'../../src/array-iterator.js',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment