2011-09-22 13:54:53 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-03-21 09:28:26 +00:00
|
|
|
// We change the stack size for the ARM64 simulator because at one point this
|
|
|
|
// test enters an infinite recursion which goes through the runtime and we
|
|
|
|
// overflow the system stack before the simulator stack.
|
2014-02-12 09:19:30 +00:00
|
|
|
|
2016-03-21 19:39:16 +00:00
|
|
|
// Flags: --sim-stack-size=500 --allow-natives-syntax
|
2011-09-13 11:42:57 +00:00
|
|
|
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
// Helper.
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestWithProxies(test, x, y, z) {
|
2015-12-11 14:55:20 +00:00
|
|
|
// Separate function for nicer stack traces.
|
|
|
|
TestWithObjectProxy(test, x, y, z);
|
|
|
|
TestWithFunctionProxy(test, x, y, z);
|
2011-09-13 11:42:57 +00:00
|
|
|
}
|
2011-07-19 09:38:59 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
function TestWithObjectProxy(test, x, y, z) {
|
|
|
|
test((handler) => { return new Proxy({}, handler) }, x, y, z)
|
|
|
|
|
|
|
|
}
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
function TestWithFunctionProxy(test, x, y, z) {
|
2016-01-07 14:48:57 +00:00
|
|
|
test((handler) => { return new Proxy(() => {}, handler) }, x, y, z)
|
2015-12-11 14:55:20 +00:00
|
|
|
}
|
2011-09-16 13:38:30 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-16 13:38:30 +00:00
|
|
|
// Getting property descriptors (Object.getOwnPropertyDescriptor).
|
|
|
|
|
|
|
|
var key
|
|
|
|
|
|
|
|
function TestGetOwnProperty(handler) {
|
|
|
|
TestWithProxies(TestGetOwnProperty2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestGetOwnProperty2(create, handler) {
|
2011-09-16 13:38:30 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertEquals(42, Object.getOwnPropertyDescriptor(p, "a").value)
|
|
|
|
assertEquals("a", key)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(42, Object.getOwnPropertyDescriptor(p, 99).value)
|
|
|
|
assertEquals("99", key)
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetOwnProperty({
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor(target, k) {
|
2011-09-16 13:38:30 +00:00
|
|
|
key = k
|
|
|
|
return {value: 42, configurable: true}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnProperty({
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor(target, k) {
|
2011-09-16 13:38:30 +00:00
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor2(k) {
|
2011-09-16 13:38:30 +00:00
|
|
|
key = k
|
|
|
|
return {value: 42, configurable: true}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnProperty({
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor(target, k) {
|
2011-09-16 13:38:30 +00:00
|
|
|
key = k
|
|
|
|
return {get value() { return 42 }, get configurable() { return true }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-11-13 14:13:50 +00:00
|
|
|
TestGetOwnProperty(new Proxy({}, {
|
2015-12-11 14:55:20 +00:00
|
|
|
get(target, pk, receiver) {
|
|
|
|
return function(t, k) { key = k; return {value: 42, configurable: true} }
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-16 13:38:30 +00:00
|
|
|
function TestGetOwnPropertyThrow(handler) {
|
|
|
|
TestWithProxies(TestGetOwnPropertyThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestGetOwnPropertyThrow2(create, handler) {
|
2011-09-16 13:38:30 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.getOwnPropertyDescriptor(p, "a"), "myexn")
|
|
|
|
assertThrowsEquals(() => Object.getOwnPropertyDescriptor(p, 77), "myexn")
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
2016-01-07 14:48:57 +00:00
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
2011-09-16 13:38:30 +00:00
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {get value() { throw "myexn" }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestGetOwnPropertyThrow(new Proxy({}, {
|
2011-09-16 13:38:30 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-16 13:38:30 +00:00
|
|
|
// Getters (dot, brackets).
|
|
|
|
|
|
|
|
var key
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
|
|
|
function TestGet(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestGet2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestGet2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertEquals(42, p.a)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals("a", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(42, p["b"])
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals("b", key)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(42, p[99])
|
|
|
|
assertEquals("99", key)
|
2011-10-26 09:31:40 +00:00
|
|
|
assertEquals(42, (function(n) { return p[n] })("c"))
|
|
|
|
assertEquals("c", key)
|
|
|
|
assertEquals(42, (function(n) { return p[n] })(101))
|
|
|
|
assertEquals("101", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
var o = Object.create(p, {x: {value: 88}})
|
|
|
|
assertEquals(42, o.a)
|
|
|
|
assertEquals("a", key)
|
|
|
|
assertEquals(42, o["b"])
|
|
|
|
assertEquals("b", key)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(42, o[99])
|
|
|
|
assertEquals("99", key)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(88, o.x)
|
|
|
|
assertEquals(88, o["x"])
|
2011-10-26 09:31:40 +00:00
|
|
|
assertEquals(42, (function(n) { return o[n] })("c"))
|
|
|
|
assertEquals("c", key)
|
|
|
|
assertEquals(42, (function(n) { return o[n] })(101))
|
|
|
|
assertEquals("101", key)
|
|
|
|
assertEquals(88, (function(n) { return o[n] })("x"))
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
}
|
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestGet({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(t, k, r) { key = k; return 42 }
|
2011-06-03 10:15:49 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestGet({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(t, k, r) { return this.get2(r, k) },
|
|
|
|
get2(r, k) { key = k; return 42 }
|
2011-06-03 10:15:49 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestGet(new Proxy({}, {
|
|
|
|
get(pt, pk, pr) {
|
|
|
|
return function(t, k, r) { key = k; return 42 }
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
|
|
|
}))
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-13 11:57:15 +00:00
|
|
|
function TestGetCall(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestGetCall2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestGetCall2(create, handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
var p = create(handler)
|
2011-07-13 11:57:15 +00:00
|
|
|
assertEquals(55, p.f())
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(55, p["f"]())
|
2011-07-13 11:57:15 +00:00
|
|
|
assertEquals(55, p.f("unused", "arguments"))
|
|
|
|
assertEquals(55, p.f.call(p))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(55, p["f"].call(p))
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(55, p[101].call(p))
|
2011-07-13 11:57:15 +00:00
|
|
|
assertEquals(55, p.withargs(45, 5))
|
|
|
|
assertEquals(55, p.withargs.call(p, 11, 22))
|
2011-10-26 09:31:40 +00:00
|
|
|
assertEquals(55, (function(n) { return p[n]() })("f"))
|
|
|
|
assertEquals(55, (function(n) { return p[n].call(p) })("f"))
|
|
|
|
assertEquals(55, (function(n) { return p[n](15, 20) })("withargs"))
|
|
|
|
assertEquals(55, (function(n) { return p[n].call(p, 13, 21) })("withargs"))
|
2011-07-13 11:57:15 +00:00
|
|
|
assertEquals("6655", "66" + p) // calls p.toString
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
var o = Object.create(p, {g: {value: function(x) { return x + 88 }}})
|
|
|
|
assertEquals(55, o.f())
|
|
|
|
assertEquals(55, o["f"]())
|
|
|
|
assertEquals(55, o.f("unused", "arguments"))
|
|
|
|
assertEquals(55, o.f.call(o))
|
|
|
|
assertEquals(55, o.f.call(p))
|
|
|
|
assertEquals(55, o["f"].call(p))
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(55, o[101].call(p))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(55, o.withargs(45, 5))
|
|
|
|
assertEquals(55, o.withargs.call(p, 11, 22))
|
|
|
|
assertEquals(90, o.g(2))
|
|
|
|
assertEquals(91, o.g.call(o, 3))
|
|
|
|
assertEquals(92, o.g.call(p, 4))
|
2011-10-26 09:31:40 +00:00
|
|
|
assertEquals(55, (function(n) { return o[n]() })("f"))
|
|
|
|
assertEquals(55, (function(n) { return o[n].call(o) })("f"))
|
|
|
|
assertEquals(55, (function(n) { return o[n](15, 20) })("withargs"))
|
|
|
|
assertEquals(55, (function(n) { return o[n].call(o, 13, 21) })("withargs"))
|
|
|
|
assertEquals(93, (function(n) { return o[n](5) })("g"))
|
|
|
|
assertEquals(94, (function(n) { return o[n].call(o, 6) })("g"))
|
|
|
|
assertEquals(95, (function(n) { return o[n].call(p, 7) })("g"))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals("6655", "66" + o) // calls o.toString
|
2011-07-13 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetCall({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(t, k, r) { return () => { return 55 } }
|
2011-07-13 11:57:15 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(t, k, r) { return this.get2(t, k, r) },
|
|
|
|
get2(t, k, r) { return () => { return 55 } }
|
2011-07-13 11:57:15 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(t, k, r) {
|
2011-07-13 11:57:15 +00:00
|
|
|
if (k == "gg") {
|
2015-12-11 14:55:20 +00:00
|
|
|
return () => { return 55 }
|
2011-07-13 11:57:15 +00:00
|
|
|
} else if (k == "withargs") {
|
2015-12-11 14:55:20 +00:00
|
|
|
return (n, m) => { return n + m * 2 }
|
2011-07-13 11:57:15 +00:00
|
|
|
} else {
|
2015-12-11 14:55:20 +00:00
|
|
|
return () => { return r.gg() }
|
2011-07-13 11:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestGetCall(new Proxy({}, {
|
|
|
|
get(pt, pk, pr) {
|
|
|
|
return (t, k, r) => { return () => { return 55 } }
|
2011-07-13 11:57:15 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestGetThrow(handler) {
|
|
|
|
TestWithProxies(TestGetThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestGetThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ p.a }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ p["b"] }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ p[3] }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ (function(n) { p[n] })("c") }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ (function(n) { p[n] })(99) }, "myexn")
|
2011-09-16 13:38:30 +00:00
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
var o = Object.create(p, {x: {value: 88}, '4': {value: 89}})
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ o.a }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ o["b"] }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ o[3] }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ (function(n) { o[n] })("c") }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ (function(n) { o[n] })(99) }, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(r, k) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
get(r, k) { return this.get2(r, k) },
|
|
|
|
get2(r, k) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestGetThrow(new Proxy({}, {
|
|
|
|
get(pr, pk) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestGetThrow(new Proxy({}, {
|
|
|
|
get(pr, pk) {
|
2011-09-13 13:07:20 +00:00
|
|
|
return function(r, k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
// Setters.
|
|
|
|
|
|
|
|
var key
|
|
|
|
var val
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestSet(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestSet2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestSet2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertEquals(42, p.a = 42)
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
assertEquals("a", key)
|
|
|
|
assertEquals(42, val)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(43, p["b"] = 43)
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
assertEquals("b", key)
|
|
|
|
assertEquals(43, val)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(44, p[77] = 44)
|
|
|
|
assertEquals("77", key)
|
|
|
|
assertEquals(44, val)
|
2011-10-26 09:31:40 +00:00
|
|
|
|
|
|
|
assertEquals(45, (function(n) { return p[n] = 45 })("c"))
|
|
|
|
assertEquals("c", key)
|
|
|
|
assertEquals(45, val)
|
|
|
|
assertEquals(46, (function(n) { return p[n] = 46 })(99))
|
|
|
|
assertEquals("99", key)
|
|
|
|
assertEquals(46, val)
|
2015-07-13 10:46:28 +00:00
|
|
|
|
|
|
|
assertEquals(47, p["0"] = 47)
|
|
|
|
assertEquals("0", key)
|
|
|
|
assertEquals(47, val)
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
}
|
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
set: function(r, k, v) { key = k; val = v; return true }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
set: function(r, k, v) { return this.set2(r, k, v) },
|
|
|
|
set2: function(r, k, v) { key = k; val = v; return true }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestSet(new Proxy({}, {
|
|
|
|
get(pk, pr) {
|
|
|
|
return (r, k, v) => { key = k; val = v; return true }
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
|
|
|
}))
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestSetThrow(handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
TestWithProxies(TestSetThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestSetThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ p.a = 42 }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ p["b"] = 42 }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ p[22] = 42 }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ (function(n) { p[n] = 45 })("c") }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ (function(n) { p[n] = 46 })(99) }, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
set: function(r, k, v) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
set: function(r, k, v) { return this.set2(r, k, v) },
|
|
|
|
set2: function(r, k, v) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
2016-01-07 14:48:57 +00:00
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {configurable: true, writable: true}
|
|
|
|
},
|
2011-09-13 13:07:20 +00:00
|
|
|
defineProperty: function(k, desc) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" },
|
|
|
|
defineProperty: function(k, desc) { this.defineProperty2(k, desc) },
|
|
|
|
defineProperty2: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
2016-01-07 14:48:57 +00:00
|
|
|
getOwnPropertyDescriptor2: function(k) {
|
|
|
|
return {configurable: true, writable: true}
|
|
|
|
},
|
2011-09-13 13:07:20 +00:00
|
|
|
defineProperty: function(k, desc) { this.defineProperty2(k, desc) },
|
|
|
|
defineProperty2: function(k, desc) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
2016-01-07 14:48:57 +00:00
|
|
|
return {
|
|
|
|
get configurable() { return true },
|
|
|
|
get writable() { return true }
|
|
|
|
}
|
2011-09-13 13:07:20 +00:00
|
|
|
},
|
|
|
|
defineProperty: function(k, desc) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestSetThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestSetThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k, v) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-16 13:38:30 +00:00
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
// Evil proxy-induced side-effects shouldn't crash.
|
|
|
|
TestWithProxies(function(create) {
|
|
|
|
var calls = 0
|
|
|
|
var handler = {
|
|
|
|
getPropertyDescriptor: function() {
|
|
|
|
++calls
|
|
|
|
return (calls % 2 == 1)
|
|
|
|
? {get: function() { return 5 }, configurable: true}
|
|
|
|
: {set: function() { return false }, configurable: true}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var p = create(handler)
|
|
|
|
var o = Object.create(p)
|
|
|
|
// Make proxy prototype property read-only after CanPut check.
|
|
|
|
try { o.x = 4 } catch (e) { assertInstanceof(e, Error) }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestWithProxies(function(create) {
|
|
|
|
var handler = {
|
|
|
|
getPropertyDescriptor: function() {
|
|
|
|
Object.defineProperty(o, "x", {get: function() { return 5 }});
|
|
|
|
return {set: function() {}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var p = create(handler)
|
|
|
|
var o = Object.create(p)
|
|
|
|
// Make object property read-only after CanPut check.
|
|
|
|
try { o.x = 4 } catch (e) { assertInstanceof(e, Error) }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-13 11:57:15 +00:00
|
|
|
// Property definition (Object.defineProperty and Object.defineProperties).
|
2011-07-07 12:41:20 +00:00
|
|
|
|
|
|
|
var key
|
|
|
|
var desc
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
function TestDefine(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestDefine2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestDefine2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertEquals(p, Object.defineProperty(p, "a", {value: 44}))
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals("a", key)
|
|
|
|
assertEquals(1, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(44, desc.value)
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, "b", {value: 45, writable: false}))
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals("b", key)
|
|
|
|
assertEquals(2, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(45, desc.value)
|
|
|
|
assertEquals(false, desc.writable)
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, "c", {value: 46, enumerable: false}))
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals("c", key)
|
|
|
|
assertEquals(2, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(46, desc.value)
|
|
|
|
assertEquals(false, desc.enumerable)
|
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, 101, {value: 47, enumerable: false}))
|
|
|
|
assertEquals("101", key)
|
|
|
|
assertEquals(2, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(47, desc.value)
|
|
|
|
assertEquals(false, desc.enumerable)
|
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
var attributes = {configurable: true, mine: 66, minetoo: 23}
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, "d", attributes))
|
2015-12-11 14:55:20 +00:00
|
|
|
assertEquals("d", key);
|
2011-07-07 12:41:20 +00:00
|
|
|
// Modifying the attributes object after the fact should have no effect.
|
|
|
|
attributes.configurable = false
|
|
|
|
attributes.mine = 77
|
2015-12-11 14:55:20 +00:00
|
|
|
delete attributes.minetoo;
|
|
|
|
assertEquals(1, Object.getOwnPropertyNames(desc).length)
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals(true, desc.configurable)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertEquals(undefined, desc.mine)
|
|
|
|
assertEquals(undefined, desc.minetoo)
|
2011-07-07 12:41:20 +00:00
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, "e", {get: function(){ return 5 }}))
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals("e", key)
|
|
|
|
assertEquals(1, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(5, desc.get())
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, "zzz", {}))
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals("zzz", key)
|
|
|
|
assertEquals(0, Object.getOwnPropertyNames(desc).length)
|
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
var props = {
|
2011-09-22 10:45:37 +00:00
|
|
|
'11': {},
|
2011-07-13 11:57:15 +00:00
|
|
|
blub: {get: function() { return true }},
|
|
|
|
'': {get value() { return 20 }},
|
|
|
|
last: {value: 21, configurable: true, mine: "eyes"}
|
|
|
|
}
|
|
|
|
Object.defineProperty(props, "hidden", {value: "hidden", enumerable: false})
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperties(p, props))
|
2011-07-13 11:57:15 +00:00
|
|
|
assertEquals("last", key)
|
|
|
|
assertEquals(2, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(21, desc.value)
|
|
|
|
assertEquals(true, desc.configurable)
|
|
|
|
assertEquals(undefined, desc.mine) // Arguably a bug in the spec...
|
2011-09-13 13:07:20 +00:00
|
|
|
|
|
|
|
var props = {bla: {get value() { throw "myexn" }}}
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ Object.defineProperties(p, props) }, "myexn")
|
2011-07-07 12:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestDefine({
|
2015-12-11 14:55:20 +00:00
|
|
|
defineProperty(t, k, d) { key = k; desc = d; return true }
|
2011-07-07 12:41:20 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
TestDefine({
|
2015-12-11 14:55:20 +00:00
|
|
|
defineProperty(t, k, d) { return this.defineProperty2(k, d) },
|
|
|
|
defineProperty2(k, d) { key = k; desc = d; return true }
|
2011-07-07 12:41:20 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestDefineThrow(handler) {
|
|
|
|
TestWithProxies(TestDefineThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestDefineThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.defineProperty(p, "a", {value: 44}), "myexn")
|
|
|
|
assertThrowsEquals(() => Object.defineProperty(p, 0, {value: 44}), "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
|
2011-10-24 15:56:18 +00:00
|
|
|
var d1 = create({
|
|
|
|
get: function(r, k) { throw "myexn" },
|
|
|
|
getOwnPropertyNames: function() { return ["value"] }
|
|
|
|
})
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ Object.defineProperty(p, "p", d1) }, "myexn")
|
2011-10-24 15:56:18 +00:00
|
|
|
var d2 = create({
|
|
|
|
get: function(r, k) { return 77 },
|
|
|
|
getOwnPropertyNames: function() { throw "myexn" }
|
|
|
|
})
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ Object.defineProperty(p, "p", d2) }, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
|
|
|
|
var props = {bla: {get value() { throw "otherexn" }}}
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.defineProperties(p, props), "otherexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestDefineThrow({
|
|
|
|
defineProperty: function(k, d) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestDefineThrow({
|
|
|
|
defineProperty: function(k, d) { return this.defineProperty2(k, d) },
|
|
|
|
defineProperty2: function(k, d) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestDefineThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestDefineThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k, d) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-15 09:10:20 +00:00
|
|
|
// Property deletion (delete).
|
|
|
|
|
|
|
|
var key
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-07-15 09:10:20 +00:00
|
|
|
function TestDelete(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestDelete2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestDelete2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertEquals(true, delete p.a)
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("a", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(true, delete p["b"])
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("b", key)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(true, delete p[1])
|
|
|
|
assertEquals("1", key)
|
2011-07-15 09:10:20 +00:00
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(false, delete p.z1)
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("z1", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(false, delete p["z2"])
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("z2", key);
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
"use strict"
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(true, delete p.c)
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("c", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(true, delete p["d"])
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("d", key)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(true, delete p[2])
|
|
|
|
assertEquals("2", key)
|
2011-07-15 09:10:20 +00:00
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertThrows(function(){ delete p.z3 }, TypeError)
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("z3", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertThrows(function(){ delete p["z4"] }, TypeError)
|
2011-07-15 09:10:20 +00:00
|
|
|
assertEquals("z4", key)
|
|
|
|
})()
|
|
|
|
}
|
|
|
|
|
|
|
|
TestDelete({
|
2015-12-11 14:55:20 +00:00
|
|
|
deleteProperty(target, k) { key = k; return k < "z" }
|
2011-07-15 09:10:20 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-15 09:10:20 +00:00
|
|
|
TestDelete({
|
2015-12-11 14:55:20 +00:00
|
|
|
deleteProperty(target, k) { return this.delete2(k) },
|
2011-07-15 09:10:20 +00:00
|
|
|
delete2: function(k) { key = k; return k < "z" }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestDelete(new Proxy({}, {
|
|
|
|
get(pt, pk, pr) {
|
|
|
|
return (target, k) => { key = k; return k < "z" }
|
2011-07-15 09:10:20 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestDeleteThrow(handler) {
|
|
|
|
TestWithProxies(TestDeleteThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestDeleteThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ delete p.a }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ delete p["b"] }, "myexn");
|
|
|
|
assertThrowsEquals(function(){ delete p[3] }, "myexn");
|
2011-09-13 13:07:20 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
"use strict"
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ delete p.c }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ delete p["d"] }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ delete p[4] }, "myexn");
|
2011-09-13 13:07:20 +00:00
|
|
|
})()
|
|
|
|
}
|
|
|
|
|
|
|
|
TestDeleteThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
deleteProperty(t, k) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestDeleteThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
deleteProperty(t, k) { return this.delete2(k) },
|
|
|
|
delete2(k) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestDeleteThrow(new Proxy({}, {
|
|
|
|
get(pt, pk, pr) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestDeleteThrow(new Proxy({}, {
|
|
|
|
get(pt, pk, pr) {
|
|
|
|
return (k) => { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-13 11:57:15 +00:00
|
|
|
// Property descriptors (Object.getOwnPropertyDescriptor).
|
|
|
|
|
|
|
|
function TestDescriptor(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestDescriptor2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestDescriptor2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2011-07-13 11:57:15 +00:00
|
|
|
var descs = [
|
|
|
|
{configurable: true},
|
|
|
|
{value: 34, enumerable: true, configurable: true},
|
|
|
|
{value: 3, writable: false, mine: "eyes", configurable: true},
|
|
|
|
{get value() { return 20 }, get configurable() { return true }},
|
|
|
|
{get: function() { "get" }, set: function() { "set" }, configurable: true}
|
|
|
|
]
|
|
|
|
for (var i = 0; i < descs.length; ++i) {
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(p, Object.defineProperty(p, i, descs[i]))
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(p, i)
|
|
|
|
for (prop in descs[i]) {
|
2011-07-13 11:57:15 +00:00
|
|
|
// TODO(rossberg): Ignore user attributes as long as the spec isn't
|
|
|
|
// fixed suitably.
|
2011-09-13 13:07:20 +00:00
|
|
|
if (prop != "mine") assertEquals(descs[i][prop], desc[prop])
|
2011-07-13 11:57:15 +00:00
|
|
|
}
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(undefined, Object.getOwnPropertyDescriptor(p, "absent"))
|
2011-07-13 11:57:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TestDescriptor({
|
2015-12-11 14:55:20 +00:00
|
|
|
defineProperty(t, k, d) { this["__" + k] = d; return true },
|
|
|
|
getOwnPropertyDescriptor(t, k) { return this["__" + k] }
|
2011-07-13 11:57:15 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestDescriptor({
|
2015-12-11 14:55:20 +00:00
|
|
|
defineProperty(t, k, d) { this["__" + k] = d; return true },
|
|
|
|
getOwnPropertyDescriptor(t, k) {
|
2011-07-13 11:57:15 +00:00
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { return this["__" + k] }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestDescriptorThrow(handler) {
|
|
|
|
TestWithProxies(TestDescriptorThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestDescriptorThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.getOwnPropertyDescriptor(p, "a"), "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestDescriptorThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestDescriptorThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
// Comparison.
|
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
function TestComparison(eq) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestComparison2, eq)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestComparison2(create, eq) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p1 = create({})
|
|
|
|
var p2 = create({})
|
|
|
|
|
|
|
|
assertTrue(eq(p1, p1))
|
|
|
|
assertTrue(eq(p2, p2))
|
|
|
|
assertTrue(!eq(p1, p2))
|
|
|
|
assertTrue(!eq(p1, {}))
|
|
|
|
assertTrue(!eq({}, p2))
|
2011-06-03 10:15:49 +00:00
|
|
|
assertTrue(!eq({}, {}))
|
|
|
|
}
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestComparison(function(o1, o2) { return o1 == o2 })
|
|
|
|
TestComparison(function(o1, o2) { return o1 === o2 })
|
|
|
|
TestComparison(function(o1, o2) { return !(o1 != o2) })
|
|
|
|
TestComparison(function(o1, o2) { return !(o1 !== o2) })
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
// Type (typeof).
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
function TestTypeof() {
|
2015-12-11 14:55:20 +00:00
|
|
|
assertEquals("object", typeof new Proxy({},{}))
|
|
|
|
assertTrue(typeof new Proxy({}, {}) == "object")
|
|
|
|
assertTrue("object" == typeof new Proxy({},{}))
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
assertEquals("function", typeof new Proxy(function() {}, {}))
|
|
|
|
assertTrue(typeof new Proxy(function() {}, {}) == "function")
|
|
|
|
assertTrue("function" == typeof new Proxy(function() {},{}))
|
2011-09-13 11:42:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestTypeof()
|
2011-06-03 10:15:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-21 11:20:27 +00:00
|
|
|
// Membership test (in).
|
2011-07-19 09:38:59 +00:00
|
|
|
|
|
|
|
var key
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
function TestIn(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestIn2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestIn2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertTrue("a" in p)
|
2011-07-19 09:38:59 +00:00
|
|
|
assertEquals("a", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertTrue(99 in p)
|
2011-07-19 09:38:59 +00:00
|
|
|
assertEquals("99", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertFalse("z" in p)
|
2011-07-19 09:38:59 +00:00
|
|
|
assertEquals("z", key)
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals(2, ("a" in p) ? 2 : 0)
|
|
|
|
assertEquals(0, !("a" in p) ? 2 : 0)
|
|
|
|
assertEquals(0, ("zzz" in p) ? 2 : 0)
|
|
|
|
assertEquals(2, !("zzz" in p) ? 2 : 0)
|
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
// Test compilation in conditionals.
|
2011-09-13 13:07:20 +00:00
|
|
|
if ("b" in p) {
|
2011-07-19 09:38:59 +00:00
|
|
|
} else {
|
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("b", key)
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
if ("zz" in p) {
|
2011-07-19 09:38:59 +00:00
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("zz", key)
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
if (!("c" in p)) {
|
2011-07-19 09:38:59 +00:00
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("c", key)
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
if (!("zzz" in p)) {
|
2011-07-19 09:38:59 +00:00
|
|
|
} else {
|
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("zzz", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
TestIn({
|
2015-12-11 14:55:20 +00:00
|
|
|
has(t, k) { key = k; return k < "z" }
|
2011-07-19 09:38:59 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
TestIn({
|
2015-12-11 14:55:20 +00:00
|
|
|
has(t, k) { return this.has2(k) },
|
|
|
|
has2(k) { key = k; return k < "z" }
|
2011-07-19 09:38:59 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestIn(new Proxy({},{
|
|
|
|
get(pt, pk, pr) {
|
|
|
|
return (t, k) => { key = k; return k < "z" }
|
2011-07-19 09:38:59 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestInThrow(handler) {
|
|
|
|
TestWithProxies(TestInThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestInThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ return "a" in p }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ return 99 in p }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ return !("a" in p) }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ return ("a" in p) ? 2 : 3 }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ if ("b" in p) {} }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ if (!("b" in p)) {} }, "myexn")
|
|
|
|
assertThrowsEquals(function(){ if ("zzz" in p) {} }, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestInThrow({
|
|
|
|
has: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInThrow({
|
|
|
|
has: function(k) { return this.has2(k) },
|
|
|
|
has2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestInThrow(new Proxy({},{
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestInThrow(new Proxy({},{
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-21 12:45:51 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-21 11:20:27 +00:00
|
|
|
// Own Properties (Object.prototype.hasOwnProperty).
|
|
|
|
|
|
|
|
var key
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
function TestHasOwn(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestHasOwn2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestHasOwn2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertTrue(Object.prototype.hasOwnProperty.call(p, "a"))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("a", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertTrue(Object.prototype.hasOwnProperty.call(p, 99))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("99", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertFalse(Object.prototype.hasOwnProperty.call(p, "z"))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("z", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
TestHasOwn({
|
2015-12-17 12:12:02 +00:00
|
|
|
getOwnPropertyDescriptor(t, k) {
|
|
|
|
key = k; if (k < "z") return {configurable: true}
|
|
|
|
},
|
|
|
|
has() { assertUnreachable() }
|
2011-07-21 11:20:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn({
|
2015-12-17 12:12:02 +00:00
|
|
|
getOwnPropertyDescriptor(t, k) { return this.getOwnPropertyDescriptor2(k) },
|
|
|
|
getOwnPropertyDescriptor2(k) {
|
|
|
|
key = k; if (k < "z") return {configurable: true}
|
|
|
|
}
|
2011-07-21 11:20:27 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestHasOwnThrow(handler) {
|
|
|
|
TestWithProxies(TestHasOwnThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestHasOwnThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ Object.prototype.hasOwnProperty.call(p, "a")},
|
2011-09-13 13:07:20 +00:00
|
|
|
"myexn")
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ Object.prototype.hasOwnProperty.call(p, 99)},
|
2011-09-13 13:07:20 +00:00
|
|
|
"myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
2015-12-17 12:12:02 +00:00
|
|
|
getOwnPropertyDescriptor(t, k) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
2015-12-17 12:12:02 +00:00
|
|
|
getOwnPropertyDescriptor(t, k) { return this.getOwnPropertyDescriptor2(k) },
|
|
|
|
getOwnPropertyDescriptor2(k) { throw "myexn" }
|
|
|
|
});
|
2011-09-13 13:07:20 +00:00
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-21 11:20:27 +00:00
|
|
|
// Instanceof (instanceof)
|
2011-06-03 10:15:49 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
(function TestProxyInstanceof() {
|
2011-09-16 13:38:30 +00:00
|
|
|
var o1 = {}
|
2015-12-11 14:55:20 +00:00
|
|
|
var p1 = new Proxy({}, {})
|
|
|
|
var p2 = new Proxy(o1, {})
|
|
|
|
var p3 = new Proxy(p2, {})
|
2011-09-16 13:38:30 +00:00
|
|
|
var o2 = Object.create(p2)
|
2011-06-03 10:15:49 +00:00
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
var f0 = function() {}
|
2011-09-16 13:38:30 +00:00
|
|
|
f0.prototype = o1
|
2011-06-03 10:15:49 +00:00
|
|
|
var f1 = function() {}
|
|
|
|
f1.prototype = p1
|
|
|
|
var f2 = function() {}
|
|
|
|
f2.prototype = p2
|
2011-09-16 13:38:30 +00:00
|
|
|
var f3 = function() {}
|
|
|
|
f3.prototype = o2
|
|
|
|
|
|
|
|
assertTrue(o1 instanceof Object)
|
|
|
|
assertFalse(o1 instanceof f0)
|
|
|
|
assertFalse(o1 instanceof f1)
|
|
|
|
assertFalse(o1 instanceof f2)
|
|
|
|
assertFalse(o1 instanceof f3)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertTrue(p1 instanceof Object)
|
2011-09-13 11:42:57 +00:00
|
|
|
assertFalse(p1 instanceof f0)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertFalse(p1 instanceof f1)
|
|
|
|
assertFalse(p1 instanceof f2)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(p1 instanceof f3)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertTrue(p2 instanceof Object)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertFalse(p2 instanceof f0)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertFalse(p2 instanceof f1)
|
|
|
|
assertFalse(p2 instanceof f2)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(p2 instanceof f3)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertTrue(p3 instanceof Object)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertFalse(p3 instanceof f0)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertFalse(p3 instanceof f1)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertFalse(p3 instanceof f2)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(p3 instanceof f3)
|
|
|
|
assertTrue(o2 instanceof Object)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertFalse(o2 instanceof f0)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(o2 instanceof f1)
|
|
|
|
assertTrue(o2 instanceof f2)
|
|
|
|
assertFalse(o2 instanceof f3)
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
var f = new Proxy(function() {}, {})
|
2011-09-13 11:42:57 +00:00
|
|
|
assertTrue(f instanceof Function)
|
2015-12-11 14:55:20 +00:00
|
|
|
})();
|
2011-11-10 13:39:22 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
(function TestInstanceofProxy() {
|
2011-11-10 13:39:22 +00:00
|
|
|
var o0 = Object.create(null)
|
|
|
|
var o1 = {}
|
|
|
|
var o2 = Object.create(o0)
|
|
|
|
var o3 = Object.create(o1)
|
|
|
|
var o4 = Object.create(o2)
|
|
|
|
var o5 = Object.create(o3)
|
|
|
|
|
2016-03-17 12:40:05 +00:00
|
|
|
function handler(o) {
|
|
|
|
return {
|
|
|
|
get: function(r, p) {
|
|
|
|
// We want to test prototype lookup, so ensure the proxy
|
|
|
|
// offers OrdinaryHasInstance behavior.
|
|
|
|
if (p === Symbol.hasInstance) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
var f0 = new Proxy(function() {}, handler(o0))
|
|
|
|
var f1 = new Proxy(function() {}, handler(o1))
|
|
|
|
var f2 = new Proxy(function() {}, handler(o2))
|
|
|
|
var f3 = new Proxy(function() {}, handler(o3))
|
|
|
|
var f4 = new Proxy(function() {}, handler(o4))
|
|
|
|
var f5 = new Proxy(function() {}, handler(o4))
|
2011-11-10 13:39:22 +00:00
|
|
|
|
|
|
|
assertFalse(null instanceof f0)
|
|
|
|
assertFalse(o0 instanceof f0)
|
|
|
|
assertFalse(o0 instanceof f1)
|
|
|
|
assertFalse(o0 instanceof f2)
|
|
|
|
assertFalse(o0 instanceof f3)
|
|
|
|
assertFalse(o0 instanceof f4)
|
|
|
|
assertFalse(o0 instanceof f5)
|
|
|
|
assertFalse(o1 instanceof f0)
|
|
|
|
assertFalse(o1 instanceof f1)
|
|
|
|
assertFalse(o1 instanceof f2)
|
|
|
|
assertFalse(o1 instanceof f3)
|
|
|
|
assertFalse(o1 instanceof f4)
|
|
|
|
assertFalse(o1 instanceof f5)
|
|
|
|
assertTrue(o2 instanceof f0)
|
|
|
|
assertFalse(o2 instanceof f1)
|
|
|
|
assertFalse(o2 instanceof f2)
|
|
|
|
assertFalse(o2 instanceof f3)
|
|
|
|
assertFalse(o2 instanceof f4)
|
|
|
|
assertFalse(o2 instanceof f5)
|
|
|
|
assertFalse(o3 instanceof f0)
|
|
|
|
assertTrue(o3 instanceof f1)
|
|
|
|
assertFalse(o3 instanceof f2)
|
|
|
|
assertFalse(o3 instanceof f3)
|
|
|
|
assertFalse(o3 instanceof f4)
|
|
|
|
assertFalse(o3 instanceof f5)
|
|
|
|
assertTrue(o4 instanceof f0)
|
|
|
|
assertFalse(o4 instanceof f1)
|
|
|
|
assertTrue(o4 instanceof f2)
|
|
|
|
assertFalse(o4 instanceof f3)
|
|
|
|
assertFalse(o4 instanceof f4)
|
|
|
|
assertFalse(o4 instanceof f5)
|
|
|
|
assertFalse(o5 instanceof f0)
|
|
|
|
assertTrue(o5 instanceof f1)
|
|
|
|
assertFalse(o5 instanceof f2)
|
|
|
|
assertTrue(o5 instanceof f3)
|
|
|
|
assertFalse(o5 instanceof f4)
|
|
|
|
assertFalse(o5 instanceof f5)
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
var f = new Proxy(function() {}, {})
|
|
|
|
var ff = new Proxy(function() {}, handler(Function))
|
2011-11-10 13:39:22 +00:00
|
|
|
assertTrue(f instanceof Function)
|
|
|
|
assertFalse(f instanceof ff)
|
2015-12-11 14:55:20 +00:00
|
|
|
})();
|
2011-06-03 10:15:49 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-21 11:20:27 +00:00
|
|
|
// Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf).
|
2011-06-03 10:15:49 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
(function TestPrototype() {
|
2011-09-16 13:38:30 +00:00
|
|
|
var o1 = {}
|
2015-12-11 14:55:20 +00:00
|
|
|
var p1 = new Proxy({}, {})
|
|
|
|
var p2 = new Proxy(o1, {})
|
|
|
|
var p3 = new Proxy(p2, {})
|
2011-09-16 13:38:30 +00:00
|
|
|
var o2 = Object.create(p3)
|
2011-06-03 10:15:49 +00:00
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
assertSame(Object.getPrototypeOf(o1), Object.prototype)
|
2015-12-11 14:55:20 +00:00
|
|
|
assertSame(Object.getPrototypeOf(p1), Object.prototype)
|
|
|
|
assertSame(Object.getPrototypeOf(p2), Object.prototype)
|
|
|
|
assertSame(Object.getPrototypeOf(p3), Object.prototype)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertSame(Object.getPrototypeOf(o2), p3)
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf(o1))
|
2015-12-11 14:55:20 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf(p1))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf(p2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf(p3))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf(o2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1))
|
2015-12-11 14:55:20 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p1))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o2))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o1, o1))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o1, p1))
|
2015-12-11 14:55:20 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o1, p2))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o1, p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o1, o2))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p1, p1))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p1, o1))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p1, p2))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p1, p3))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p1, o2))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p2, p1))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p2, p2))
|
2015-12-11 14:55:20 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p2, p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p2, o2))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p3, p2))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(p3, o2))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o2, o1))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o2, p1))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o2, p2))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o2, p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o2, o2))
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
var f = new Proxy(function() {}, {})
|
2011-09-13 11:42:57 +00:00
|
|
|
assertSame(Object.getPrototypeOf(f), Function.prototype)
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf(f))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f))
|
2015-12-11 14:55:20 +00:00
|
|
|
})();
|
2011-07-13 11:01:17 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestPropertyNamesThrow(handler) {
|
|
|
|
TestWithProxies(TestPropertyNamesThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestPropertyNamesThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(function(){ Object.getOwnPropertyNames(p) }, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestPropertyNamesThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestPropertyNamesThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2() { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
function TestKeys(names, handler) {
|
2015-12-11 14:55:20 +00:00
|
|
|
var p = new Proxy({}, handler);
|
2011-10-10 09:59:03 +00:00
|
|
|
assertArrayEquals(names, Object.keys(p))
|
2011-07-13 11:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestKeys([], {
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return [] }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeys([], {
|
|
|
|
ownKeys() { return ["a", "zz", " ", "0", "toString"] }
|
2011-07-13 11:01:17 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2012-05-29 13:57:55 +00:00
|
|
|
TestKeys(["a", "zz", " ", "0", "toString"], {
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return ["a", "zz", " ", "0", "toString"] },
|
|
|
|
getOwnPropertyDescriptor(t, p) {
|
|
|
|
return {configurable: true, enumerable: true}
|
|
|
|
}
|
2011-07-13 11:01:17 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestKeys([], {
|
|
|
|
ownKeys() { return this.keys2() },
|
|
|
|
keys2() { return ["throw", "function "] }
|
2011-07-13 11:01:17 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestKeys(["throw", "function "], {
|
|
|
|
ownKeys() { return this.keys2() },
|
|
|
|
keys2() { return ["throw", "function "] },
|
|
|
|
getOwnPropertyDescriptor(t, p) {
|
|
|
|
return {configurable: true, enumerable: true}
|
2011-07-13 11:01:17 +00:00
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["a", "0"], {
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return ["a", "23", "zz", "", "0"] },
|
|
|
|
getOwnPropertyDescriptor(t, k) {
|
|
|
|
return k == "" ?
|
|
|
|
undefined :
|
|
|
|
{ configurable: true, enumerable: k.length == 1}
|
2011-10-24 15:56:18 +00:00
|
|
|
}
|
2011-07-13 11:01:17 +00:00
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["23", "zz", ""], {
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2() { return ["a", "23", "zz", "", "0"] },
|
|
|
|
getOwnPropertyDescriptor(t, k) {
|
2011-07-13 11:01:17 +00:00
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor2(k) {
|
|
|
|
return {configurable: true, enumerable: k.length != 1 }
|
2011-07-13 11:01:17 +00:00
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys([], {
|
2015-12-11 14:55:20 +00:00
|
|
|
get ownKeys() {
|
2011-07-13 11:01:17 +00:00
|
|
|
return function() { return ["a", "b", "c"] }
|
|
|
|
},
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor: function(k) { return {configurable: true} }
|
2011-07-13 11:01:17 +00:00
|
|
|
})
|
2011-07-18 13:04:52 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestKeysThrow(handler) {
|
|
|
|
TestWithProxies(TestKeysThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestKeysThrow2(create, handler) {
|
2016-01-07 14:48:57 +00:00
|
|
|
var p = create(handler);
|
|
|
|
assertThrowsEquals(function(){ Object.keys(p) }, "myexn");
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return this.keys2() },
|
|
|
|
keys2() { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return ['1'] },
|
|
|
|
getOwnPropertyDescriptor: function() { throw "myexn" },
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
ownKeys() { return this.getOwnPropertyNames2() },
|
2016-01-07 14:48:57 +00:00
|
|
|
getOwnPropertyNames2() { return ['1', '2'] },
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor(k) {
|
2011-09-13 13:07:20 +00:00
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor2(k) { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
get ownKeys() { throw "myexn" }
|
2011-09-13 13:07:20 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
get ownKeys() {
|
2011-09-13 13:07:20 +00:00
|
|
|
return function() { throw "myexn" }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2014-08-07 16:42:14 +00:00
|
|
|
TestKeysThrow({
|
2015-12-11 14:55:20 +00:00
|
|
|
get ownKeys() {
|
2016-01-07 14:48:57 +00:00
|
|
|
return function() { return ['1', '2'] }
|
2011-09-13 13:07:20 +00:00
|
|
|
},
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor(k) { throw "myexn" }
|
2011-10-10 09:59:03 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 11:42:57 +00:00
|
|
|
// String conversion (Object.prototype.toString,
|
|
|
|
// Object.prototype.toLocaleString,
|
|
|
|
// Function.prototype.toString)
|
2011-07-21 11:20:27 +00:00
|
|
|
|
|
|
|
var key
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
function TestToString(handler) {
|
2015-12-11 14:55:20 +00:00
|
|
|
var p = new Proxy({}, handler)
|
2011-07-21 11:20:27 +00:00
|
|
|
key = ""
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals("[object Object]", Object.prototype.toString.call(p))
|
2016-01-08 14:56:32 +00:00
|
|
|
assertEquals(Symbol.toStringTag, key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals("my_proxy", Object.prototype.toLocaleString.call(p))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("toString", key)
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2016-01-08 14:56:32 +00:00
|
|
|
var f = new Proxy(function() {}, handler)
|
2011-09-13 11:42:57 +00:00
|
|
|
key = ""
|
|
|
|
assertEquals("[object Function]", Object.prototype.toString.call(f))
|
2016-01-08 14:56:32 +00:00
|
|
|
assertEquals(Symbol.toStringTag, key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertEquals("my_proxy", Object.prototype.toLocaleString.call(f))
|
2011-09-13 11:42:57 +00:00
|
|
|
assertEquals("toString", key)
|
2016-01-08 14:56:32 +00:00
|
|
|
assertThrows(function(){ Function.prototype.toString.call(f) })
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
var o = Object.create(p)
|
|
|
|
key = ""
|
|
|
|
assertEquals("[object Object]", Object.prototype.toString.call(o))
|
2016-01-08 14:56:32 +00:00
|
|
|
assertEquals(Symbol.toStringTag, key)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals("my_proxy", Object.prototype.toLocaleString.call(o))
|
|
|
|
assertEquals("toString", key)
|
2011-07-21 11:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestToString({
|
|
|
|
get: function(r, k) { key = k; return function() { return "my_proxy" } }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestToString({
|
|
|
|
get: function(r, k) { return this.get2(r, k) },
|
|
|
|
get2: function(r, k) { key = k; return function() { return "my_proxy" } }
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestToString(new Proxy({}, {
|
2011-07-21 11:20:27 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k) { key = k; return function() { return "my_proxy" } }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestToStringThrow(handler) {
|
2015-12-11 14:55:20 +00:00
|
|
|
var p = new Proxy({}, handler)
|
2016-01-08 14:56:32 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.toString.call(p), "myexn")
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.toLocaleString.call(p), "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
var f = new Proxy(function(){}, handler)
|
2016-01-08 14:56:32 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.toString.call(f), "myexn")
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.toLocaleString.call(f), "myexn")
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
var o = Object.create(p)
|
2016-01-08 14:56:32 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.toString.call(o), "myexn")
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.toLocaleString.call(o), "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestToStringThrow({
|
|
|
|
get: function(r, k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestToStringThrow({
|
|
|
|
get: function(r, k) { return this.get2(r, k) },
|
|
|
|
get2: function(r, k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestToStringThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestToStringThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-21 11:20:27 +00:00
|
|
|
// Value conversion (Object.prototype.toValue)
|
|
|
|
|
|
|
|
function TestValueOf(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestValueOf2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestValueOf2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertSame(p, Object.prototype.valueOf.call(p))
|
2011-07-21 11:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestValueOf({})
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-07-21 11:20:27 +00:00
|
|
|
// Enumerability (Object.prototype.propertyIsEnumerable)
|
|
|
|
|
|
|
|
var key
|
2011-09-13 11:42:57 +00:00
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
function TestIsEnumerable(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestIsEnumerable2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestIsEnumerable2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
|
|
|
assertTrue(Object.prototype.propertyIsEnumerable.call(p, "a"))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("a", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertTrue(Object.prototype.propertyIsEnumerable.call(p, 2))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("2", key)
|
2011-09-13 13:07:20 +00:00
|
|
|
assertFalse(Object.prototype.propertyIsEnumerable.call(p, "z"))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("z", key)
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
var o = Object.create(p)
|
|
|
|
key = ""
|
|
|
|
assertFalse(Object.prototype.propertyIsEnumerable.call(o, "a"))
|
|
|
|
assertEquals("", key) // trap not invoked
|
2011-07-21 11:20:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestIsEnumerable({
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor(t, k) {
|
|
|
|
key = k;
|
|
|
|
return {enumerable: k < "z", configurable: true}
|
2011-07-21 11:20:27 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerable({
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor: function(t, k) {
|
2011-07-21 11:20:27 +00:00
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) {
|
2015-12-11 14:55:20 +00:00
|
|
|
key = k;
|
|
|
|
return {enumerable: k < "z", configurable: true}
|
2011-07-21 11:20:27 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerable({
|
2015-12-11 14:55:20 +00:00
|
|
|
getOwnPropertyDescriptor: function(t, k) {
|
|
|
|
key = k;
|
|
|
|
return {get enumerable() { return k < "z" }, configurable: true}
|
2011-07-21 11:20:27 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestIsEnumerable(new Proxy({}, {
|
|
|
|
get: function(pt, pk, pr) {
|
|
|
|
return function(t, k) {
|
|
|
|
key = k;
|
|
|
|
return {enumerable: k < "z", configurable: true}
|
2011-07-21 11:20:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}))
|
2011-09-13 11:42:57 +00:00
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestIsEnumerableThrow(handler) {
|
|
|
|
TestWithProxies(TestIsEnumerableThrow2, handler)
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:59:03 +00:00
|
|
|
function TestIsEnumerableThrow2(create, handler) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = create(handler)
|
2016-01-07 14:48:57 +00:00
|
|
|
assertThrowsEquals(() => Object.prototype.propertyIsEnumerable.call(p, "a"),
|
|
|
|
"myexn")
|
|
|
|
assertThrowsEquals(() => Object.prototype.propertyIsEnumerable.call(p, 11),
|
|
|
|
"myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestIsEnumerableThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerableThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerableThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {get enumerable() { throw "myexn" }, configurable: true}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestIsEnumerableThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
TestIsEnumerableThrow(new Proxy({}, {
|
2011-09-13 13:07:20 +00:00
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
2015-12-11 14:55:20 +00:00
|
|
|
}));
|
2012-03-23 10:25:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2012-03-23 10:25:14 +00:00
|
|
|
// Constructor functions with proxy prototypes.
|
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
(function TestConstructorWithProxyPrototype() {
|
2012-03-23 10:25:14 +00:00
|
|
|
TestWithProxies(TestConstructorWithProxyPrototype2, {})
|
2015-12-11 14:55:20 +00:00
|
|
|
})();
|
2012-03-23 10:25:14 +00:00
|
|
|
|
|
|
|
function TestConstructorWithProxyPrototype2(create, handler) {
|
|
|
|
function C() {};
|
|
|
|
C.prototype = create(handler);
|
|
|
|
|
|
|
|
var o = new C;
|
|
|
|
assertSame(C.prototype, Object.getPrototypeOf(o));
|
2015-12-11 14:55:20 +00:00
|
|
|
};
|
2012-03-23 10:25:14 +00:00
|
|
|
|
2015-04-17 09:25:27 +00:00
|
|
|
|
2015-12-11 14:55:20 +00:00
|
|
|
(function TestOptWithProxyPrototype() {
|
2015-04-17 09:25:27 +00:00
|
|
|
var handler = {
|
2015-12-11 14:55:20 +00:00
|
|
|
get(t, k) {
|
|
|
|
return 10;
|
2015-04-17 09:25:27 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function C() {};
|
2015-12-11 14:55:20 +00:00
|
|
|
C.prototype = new Proxy({}, handler);
|
2015-04-17 09:25:27 +00:00
|
|
|
var o = new C();
|
|
|
|
|
|
|
|
function f() {
|
|
|
|
return o.x;
|
|
|
|
}
|
|
|
|
assertEquals(10, f());
|
|
|
|
assertEquals(10, f());
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(10, f());
|
2015-12-11 14:55:20 +00:00
|
|
|
})();
|