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.
|
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
// Flags: --harmony-proxies
|
|
|
|
|
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-21 12:45:51 +00:00
|
|
|
// TODO(rossberg): for-in not implemented on proxies.
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
// Helper.
|
|
|
|
|
|
|
|
function TestWithProxies(test, handler) {
|
|
|
|
test(handler, Proxy.create)
|
|
|
|
test(handler, function(h) {return Proxy.createFunction(h, function() {})})
|
|
|
|
}
|
2011-07-19 09:38:59 +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-16 13:38:30 +00:00
|
|
|
|
|
|
|
// Getting property descriptors (Object.getOwnPropertyDescriptor).
|
|
|
|
|
|
|
|
var key
|
|
|
|
|
|
|
|
function TestGetOwnProperty(handler) {
|
|
|
|
TestWithProxies(TestGetOwnProperty2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestGetOwnProperty2(handler, create) {
|
|
|
|
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({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k
|
|
|
|
return {value: 42, configurable: true}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnProperty({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) {
|
|
|
|
key = k
|
|
|
|
return {value: 42, configurable: true}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnProperty({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k
|
|
|
|
return {get value() { return 42 }, get configurable() { return true }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnProperty(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { key = k; return {value: 42, configurable: true} }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
function TestGetOwnPropertyThrow(handler) {
|
|
|
|
TestWithProxies(TestGetOwnPropertyThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestGetOwnPropertyThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ Object.getOwnPropertyDescriptor(p, 77) }, "myexn")
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {get value() { throw "myexn" }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetOwnPropertyThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestGet2(handler, create) {
|
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-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"])
|
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({
|
2011-09-16 13:38:30 +00:00
|
|
|
get: function(r, k) { 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({
|
|
|
|
get: function(r, k) { return this.get2(r, k) },
|
2011-09-16 13:38:30 +00:00
|
|
|
get2: function(r, k) { 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({
|
2011-09-16 13:38:30 +00:00
|
|
|
getPropertyDescriptor: function(k) { key = k; return {value: 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({
|
|
|
|
getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
2011-09-16 13:38:30 +00:00
|
|
|
getPropertyDescriptor2: function(k) { key = k; return {value: 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({
|
|
|
|
getPropertyDescriptor: function(k) {
|
2011-09-16 13:38:30 +00:00
|
|
|
key = k;
|
2011-06-03 10:15:49 +00:00
|
|
|
return {get value() { return 42 }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestGet({
|
|
|
|
get: undefined,
|
2011-09-16 13:38:30 +00:00
|
|
|
getPropertyDescriptor: function(k) { key = k; return {value: 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
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestGet(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
2011-09-16 13:38:30 +00:00
|
|
|
return function(r, k) { 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
|
|
|
|
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
function TestGetCall(handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestGetCall2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestGetCall2(handler, create) {
|
|
|
|
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))
|
|
|
|
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))
|
|
|
|
assertEquals("6655", "66" + o) // calls o.toString
|
2011-07-13 11:57:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetCall({
|
|
|
|
get: function(r, k) { return function() { return 55 } }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
|
|
|
get: function(r, k) { return this.get2(r, k) },
|
|
|
|
get2: function(r, k) { return function() { return 55 } }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {value: function() { return 55 }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
|
|
|
getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
|
|
|
getPropertyDescriptor2: function(k) {
|
|
|
|
return {value: function() { return 55 }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {get value() { return function() { return 55 } }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
|
|
|
get: undefined,
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {value: function() { return 55 }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestGetCall({
|
|
|
|
get: function(r, k) {
|
|
|
|
if (k == "gg") {
|
|
|
|
return function() { return 55 }
|
|
|
|
} else if (k == "withargs") {
|
|
|
|
return function(n, m) { return n + m * 2 }
|
|
|
|
} else {
|
|
|
|
return function() { return this.gg() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetCall(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k) { return function() { return 55 } }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestGetThrow(handler) {
|
|
|
|
TestWithProxies(TestGetThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestGetThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ p.a }, "myexn")
|
|
|
|
assertThrows(function(){ p["b"] }, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ p[3] }, "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}})
|
2011-09-16 13:38:30 +00:00
|
|
|
assertThrows(function(){ o.a }, "myexn")
|
|
|
|
assertThrows(function(){ o["b"] }, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ o[3] }, "myexn")
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(88, o.x)
|
|
|
|
assertEquals(88, o["x"])
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(89, o[4])
|
2011-09-13 13:07:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestGetThrow({
|
|
|
|
get: function(r, k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow({
|
|
|
|
get: function(r, k) { return this.get2(r, k) },
|
|
|
|
get2: function(r, k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow({
|
|
|
|
getPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow({
|
|
|
|
getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
|
|
|
getPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow({
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {get value() { throw "myexn" }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow({
|
|
|
|
get: undefined,
|
|
|
|
getPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestGetThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestGetThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
function TestSet(handler, create) {
|
|
|
|
TestWithProxies(TestSet2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestSet2(handler, create) {
|
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)
|
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
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return {writable: true} },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { return {writable: true} },
|
|
|
|
defineProperty: function(k, desc) { this.defineProperty2(k, desc) },
|
|
|
|
defineProperty2: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {get writable() { return true }}
|
|
|
|
},
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {set: function(v) { key = k; val = v }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) { return {writable: true} },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {get writable() { return true }}
|
|
|
|
},
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {set: function(v) { key = k; val = v }}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestSet({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) { return null },
|
|
|
|
defineProperty: function(k, desc) { key = k, val = desc.value }
|
|
|
|
})
|
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(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k, v) { key = k; val = v; return true }
|
|
|
|
}
|
|
|
|
}))
|
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 13:07:20 +00:00
|
|
|
function TestSetThrow(handler, create) {
|
|
|
|
TestWithProxies(TestSetThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestSetThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ p.a = 42 }, "myexn")
|
|
|
|
assertThrows(function(){ p["b"] = 42 }, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ p[22] = 42 }, "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({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return {writable: true} },
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { return {writable: true} },
|
|
|
|
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) {
|
|
|
|
return {get writable() { return true }}
|
|
|
|
},
|
|
|
|
defineProperty: function(k, desc) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return {set: function(v) { throw "myexn" }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" },
|
|
|
|
getPropertyDescriptor: function(k) { return {writable: true} },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) { throw "myexn" },
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) { return {writable: true} },
|
|
|
|
defineProperty: function(k, desc) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {get writable() { throw "myexn" }}
|
|
|
|
},
|
|
|
|
defineProperty: function(k, desc) { key = k; val = desc.value }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
return {set: function(v) { throw "myexn" }}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { return null },
|
|
|
|
getPropertyDescriptor: function(k) { return null },
|
|
|
|
defineProperty: function(k, desc) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestSetThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestSetThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k, v) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
var key
|
|
|
|
var val
|
|
|
|
|
|
|
|
function TestSetForDerived(handler, create) {
|
|
|
|
TestWithProxies(TestSetForDerived2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestSetForDerived2(handler, create) {
|
|
|
|
var p = create(handler)
|
2011-09-22 10:45:37 +00:00
|
|
|
var o = Object.create(p, {x: {value: 88, writable: true},
|
|
|
|
'1': {value: 89, writable: true}})
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
key = ""
|
|
|
|
assertEquals(48, o.x = 48)
|
|
|
|
assertEquals("", key) // trap not invoked
|
|
|
|
assertEquals(48, o.x)
|
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(47, o[1] = 47)
|
|
|
|
assertEquals("", key) // trap not invoked
|
|
|
|
assertEquals(47, o[1])
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(49, o.y = 49)
|
|
|
|
assertEquals("y", key)
|
|
|
|
assertEquals(49, o.y)
|
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
assertEquals(50, o[2] = 50)
|
|
|
|
assertEquals("2", key)
|
|
|
|
assertEquals(50, o[2])
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
assertEquals(44, o.p_writable = 44)
|
|
|
|
assertEquals("p_writable", key)
|
|
|
|
assertEquals(44, o.p_writable)
|
|
|
|
|
|
|
|
assertEquals(45, o.p_nonwritable = 45)
|
|
|
|
assertEquals("p_nonwritable", key)
|
|
|
|
assertEquals(45, o.p_nonwritable)
|
|
|
|
|
|
|
|
assertEquals(46, o.p_setter = 46)
|
|
|
|
assertEquals("p_setter", key)
|
|
|
|
assertEquals(46, val) // written to parent
|
|
|
|
assertFalse(Object.prototype.hasOwnProperty.call(o, "p_setter"))
|
|
|
|
|
|
|
|
val = ""
|
|
|
|
assertEquals(47, o.p_nosetter = 47)
|
|
|
|
assertEquals("p_nosetter", key)
|
|
|
|
assertEquals("", val) // not written at all
|
|
|
|
assertFalse(Object.prototype.hasOwnProperty.call(o, "p_nosetter"));
|
|
|
|
|
|
|
|
key = ""
|
|
|
|
assertThrows(function(){ "use strict"; o.p_nosetter = 50 }, TypeError)
|
|
|
|
assertEquals("p_nosetter", key)
|
|
|
|
assertEquals("", val) // not written at all
|
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ o.p_nonconf = 53 }, TypeError)
|
|
|
|
assertEquals("p_nonconf", key)
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
assertThrows(function(){ o.p_throw = 51 }, "myexn")
|
|
|
|
assertEquals("p_throw", key)
|
|
|
|
|
|
|
|
assertThrows(function(){ o.p_setterthrow = 52 }, "myexn")
|
|
|
|
assertEquals("p_setterthrow", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
TestSetForDerived({
|
2011-10-06 08:42:10 +00:00
|
|
|
getPropertyDescriptor: function(k) {
|
2011-09-16 13:38:30 +00:00
|
|
|
key = k;
|
|
|
|
switch (k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
case "p_writable": return {writable: true, configurable: true}
|
|
|
|
case "p_nonwritable": return {writable: false, configurable: true}
|
|
|
|
case "p_setter":return {set: function(x) { val = x }, configurable: true}
|
|
|
|
case "p_nosetter": return {get: function() { return 1 }, configurable: true}
|
|
|
|
case "p_nonconf":return {}
|
2011-09-16 13:38:30 +00:00
|
|
|
case "p_throw": throw "myexn"
|
|
|
|
case "p_setterthrow": return {set: function(x) { throw "myexn" }}
|
|
|
|
default: return undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(rossberg): TestSetReject, returning false
|
|
|
|
// TODO(rossberg): TestGetProperty, TestSetProperty
|
|
|
|
|
|
|
|
|
2011-09-13 13:07: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestDefine2(handler, create) {
|
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))
|
2011-07-07 12:41:20 +00:00
|
|
|
assertEquals("d", key)
|
|
|
|
// Modifying the attributes object after the fact should have no effect.
|
|
|
|
attributes.configurable = false
|
|
|
|
attributes.mine = 77
|
|
|
|
delete attributes.minetoo
|
|
|
|
assertEquals(3, Object.getOwnPropertyNames(desc).length)
|
|
|
|
assertEquals(true, desc.configurable)
|
|
|
|
assertEquals(66, desc.mine)
|
|
|
|
assertEquals(23, desc.minetoo)
|
|
|
|
|
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-09-13 11:42:57 +00:00
|
|
|
// TODO(rossberg): This test requires for-in on proxies.
|
|
|
|
// var d = create({
|
2011-07-07 12:41:20 +00:00
|
|
|
// get: function(r, k) { return (k === "value") ? 77 : void 0 },
|
|
|
|
// getOwnPropertyNames: function() { return ["value"] }
|
|
|
|
// })
|
|
|
|
// assertEquals(1, Object.getOwnPropertyNames(d).length)
|
|
|
|
// assertEquals(77, d.value)
|
2011-09-13 13:07:20 +00:00
|
|
|
// assertEquals(p, Object.defineProperty(p, "p", d))
|
2011-07-07 12:41:20 +00:00
|
|
|
// assertEquals("p", key)
|
|
|
|
// assertEquals(1, Object.getOwnPropertyNames(desc).length)
|
|
|
|
// assertEquals(77, desc.value)
|
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" }}}
|
|
|
|
assertThrows(function(){ Object.defineProperties(p, props) }, "myexn")
|
2011-07-07 12:41:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestDefine({
|
|
|
|
defineProperty: function(k, d) { key = k; desc = d; return true }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
TestDefine({
|
|
|
|
defineProperty: function(k, d) { return this.defineProperty2(k, d) },
|
|
|
|
defineProperty2: function(k, d) { key = k; desc = d; return true }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-07 12:41:20 +00:00
|
|
|
TestDefine(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k, d) { key = k; desc = d; return true }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestDefineThrow(handler) {
|
|
|
|
TestWithProxies(TestDefineThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestDefineThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.defineProperty(p, "a", {value: 44})}, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ Object.defineProperty(p, 0, {value: 44})}, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
|
|
|
|
// TODO(rossberg): These tests require for-in on proxies.
|
|
|
|
// var d1 = create({
|
|
|
|
// get: function(r, k) { throw "myexn" },
|
|
|
|
// getOwnPropertyNames: function() { return ["value"] }
|
|
|
|
// })
|
|
|
|
// assertThrows(function(){ Object.defineProperty(p, "p", d1) }, "myexn")
|
|
|
|
// var d2 = create({
|
|
|
|
// get: function(r, k) { return 77 },
|
|
|
|
// getOwnPropertyNames: function() { throw "myexn" }
|
|
|
|
// })
|
|
|
|
// assertThrows(function(){ Object.defineProperty(p, "p", d2) }, "myexn")
|
|
|
|
|
|
|
|
var props = {bla: {get value() { throw "otherexn" }}}
|
|
|
|
assertThrows(function(){ Object.defineProperties(p, props) }, "otherexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestDefineThrow({
|
|
|
|
defineProperty: function(k, d) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestDefineThrow({
|
|
|
|
defineProperty: function(k, d) { return this.defineProperty2(k, d) },
|
|
|
|
defineProperty2: function(k, d) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestDefineThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestDefineThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k, d) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-07-07 12:41: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestDelete2(handler, create) {
|
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({
|
2011-09-13 13:07:20 +00:00
|
|
|
delete: function(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({
|
2011-09-13 13:07:20 +00:00
|
|
|
delete: function(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
|
|
|
|
2011-07-15 09:10:20 +00:00
|
|
|
TestDelete(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { key = k; return k < "z" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestDeleteThrow(handler) {
|
|
|
|
TestWithProxies(TestDeleteThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestDeleteThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ delete p.a }, "myexn")
|
|
|
|
assertThrows(function(){ delete p["b"] }, "myexn");
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ delete p[3] }, "myexn");
|
2011-09-13 13:07:20 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
"use strict"
|
|
|
|
assertThrows(function(){ delete p.c }, "myexn")
|
|
|
|
assertThrows(function(){ delete p["d"] }, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ delete p[4] }, "myexn");
|
2011-09-13 13:07:20 +00:00
|
|
|
})()
|
|
|
|
}
|
|
|
|
|
|
|
|
TestDeleteThrow({
|
|
|
|
delete: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestDeleteThrow({
|
|
|
|
delete: function(k) { return this.delete2(k) },
|
|
|
|
delete2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestDeleteThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestDeleteThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-07-15 09:10: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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestDescriptor2(handler, create) {
|
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({
|
|
|
|
defineProperty: function(k, d) { this["__" + k] = d; return true },
|
|
|
|
getOwnPropertyDescriptor: function(k) { return this["__" + k] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:57:15 +00:00
|
|
|
TestDescriptor({
|
|
|
|
defineProperty: function(k, d) { this["__" + k] = d; return true },
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { return this["__" + k] }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestDescriptorThrow(handler) {
|
|
|
|
TestWithProxies(TestDescriptorThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestDescriptorThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.getOwnPropertyDescriptor(p, "a") }, "myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestComparison2(eq, create) {
|
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() {
|
|
|
|
assertEquals("object", typeof Proxy.create({}))
|
|
|
|
assertTrue(typeof Proxy.create({}) == "object")
|
|
|
|
assertTrue("object" == typeof Proxy.create({}))
|
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
|
|
|
assertEquals("function", typeof Proxy.createFunction({}, function() {}))
|
|
|
|
assertTrue(typeof Proxy.createFunction({}, function() {}) == "function")
|
|
|
|
assertTrue("function" == typeof Proxy.createFunction({}, function() {}))
|
|
|
|
}
|
|
|
|
|
|
|
|
TestTypeof()
|
2011-06-03 10:15:49 +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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestIn2(handler, create) {
|
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({
|
|
|
|
has: function(k) { key = k; return k < "z" }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
TestIn({
|
|
|
|
has: function(k) { return this.has2(k) },
|
|
|
|
has2: function(k) { key = k; return k < "z" }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
TestIn({
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42} : void 0
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
TestIn({
|
|
|
|
getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
|
|
|
getPropertyDescriptor2: function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42} : void 0
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
TestIn({
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
key = k; return k < "z" ? {get value() { return 42 }} : void 0
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
TestIn({
|
2011-09-16 13:38:30 +00:00
|
|
|
has: undefined,
|
2011-07-19 09:38:59 +00:00
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42} : void 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIn(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { key = k; return k < "z" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestInThrow(handler) {
|
|
|
|
TestWithProxies(TestInThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestInThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ return "a" in o }, "myexn")
|
2011-09-22 10:45:37 +00:00
|
|
|
assertThrows(function(){ return 99 in o }, "myexn")
|
2011-09-13 13:07:20 +00:00
|
|
|
assertThrows(function(){ return !("a" in o) }, "myexn")
|
|
|
|
assertThrows(function(){ return ("a" in o) ? 2 : 3 }, "myexn")
|
|
|
|
assertThrows(function(){ if ("b" in o) {} }, "myexn")
|
|
|
|
assertThrows(function(){ if (!("b" in o)) {} }, "myexn")
|
|
|
|
assertThrows(function(){ if ("zzz" in o) {} }, "myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestInThrow({
|
|
|
|
has: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInThrow({
|
|
|
|
has: function(k) { return this.has2(k) },
|
|
|
|
has2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInThrow({
|
|
|
|
getPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInThrow({
|
|
|
|
getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
|
|
|
getPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInThrow({
|
2011-09-16 13:38:30 +00:00
|
|
|
has: undefined,
|
2011-09-13 13:07:20 +00:00
|
|
|
getPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestInThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
function TestInForDerived(handler) {
|
|
|
|
TestWithProxies(TestInForDerived2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestInForDerived2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
var o = Object.create(p)
|
2011-09-22 10:45:37 +00:00
|
|
|
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue("a" in o)
|
|
|
|
assertEquals("a", key)
|
2011-09-22 10:45:37 +00:00
|
|
|
assertTrue(99 in o)
|
|
|
|
assertEquals("99", key)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse("z" in o)
|
|
|
|
assertEquals("z", key)
|
|
|
|
|
|
|
|
assertEquals(2, ("a" in o) ? 2 : 0)
|
|
|
|
assertEquals(0, !("a" in o) ? 2 : 0)
|
|
|
|
assertEquals(0, ("zzz" in o) ? 2 : 0)
|
|
|
|
assertEquals(2, !("zzz" in o) ? 2 : 0)
|
|
|
|
|
|
|
|
if ("b" in o) {
|
|
|
|
} else {
|
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("b", key)
|
|
|
|
|
|
|
|
if ("zz" in o) {
|
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("zz", key)
|
|
|
|
|
|
|
|
if (!("c" in o)) {
|
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("c", key)
|
|
|
|
|
|
|
|
if (!("zzz" in o)) {
|
|
|
|
} else {
|
|
|
|
assertTrue(false)
|
|
|
|
}
|
|
|
|
assertEquals("zzz", key)
|
|
|
|
}
|
|
|
|
|
|
|
|
TestInForDerived({
|
|
|
|
getPropertyDescriptor: function(k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
key = k; return k < "z" ? {value: 42, configurable: true} : void 0
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInForDerived({
|
|
|
|
getPropertyDescriptor: function(k) { return this.getPropertyDescriptor2(k) },
|
|
|
|
getPropertyDescriptor2: function(k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
key = k; return k < "z" ? {value: 42, configurable: true} : void 0
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInForDerived({
|
|
|
|
getPropertyDescriptor: function(k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
key = k;
|
|
|
|
return k < "z" ? {get value() { return 42 }, configurable: true} : void 0
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
/* TODO(rossberg): this will work once we implement the newest proposal
|
|
|
|
* regarding default traps for getPropertyDescriptor.
|
|
|
|
TestInForDerived({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
key = k; return k < "z" ? {value: 42, configurable: true} : void 0
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInForDerived({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
key = k; return k < "z" ? {value: 42, configurable: true} : void 0
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestInForDerived({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
2011-09-22 10:45:37 +00:00
|
|
|
key = k;
|
|
|
|
return k < "z" ? {get value() { return 42 }, configurable: true} : void 0
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
*/
|
|
|
|
|
|
|
|
TestInForDerived(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
2011-09-22 10:45:37 +00:00
|
|
|
return function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42, configurable: true} : void 0
|
|
|
|
}
|
2011-09-16 13:38:30 +00:00
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-07-19 09:38:59 +00:00
|
|
|
|
2011-09-21 12:45:51 +00:00
|
|
|
// Property descriptor conversion.
|
|
|
|
|
|
|
|
var descget
|
|
|
|
|
|
|
|
function TestDescriptorGetOrder(handler) {
|
|
|
|
var p = Proxy.create(handler)
|
|
|
|
var o = Object.create(p, {b: {value: 0}})
|
2011-09-22 10:45:37 +00:00
|
|
|
TestDescriptorGetOrder2(function(n) { return p[n] }, "vV")
|
|
|
|
TestDescriptorGetOrder2(function(n) { return n in p }, "")
|
|
|
|
TestDescriptorGetOrder2(function(n) { return o[n] }, "vV")
|
|
|
|
TestDescriptorGetOrder2(function(n) { return n in o }, "eEcCvVwWgs")
|
2011-09-21 12:45:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function TestDescriptorGetOrder2(f, access) {
|
|
|
|
descget = ""
|
2011-09-22 10:45:37 +00:00
|
|
|
assertTrue(f("a"))
|
|
|
|
assertEquals(access, descget)
|
|
|
|
descget = ""
|
|
|
|
assertTrue(f(99))
|
2011-09-21 12:45:51 +00:00
|
|
|
assertEquals(access, descget)
|
|
|
|
descget = ""
|
2011-09-22 10:45:37 +00:00
|
|
|
assertFalse(!!f("z"))
|
2011-09-21 12:45:51 +00:00
|
|
|
assertEquals("", descget)
|
|
|
|
}
|
|
|
|
|
|
|
|
TestDescriptorGetOrder({
|
|
|
|
getPropertyDescriptor: function(k) {
|
|
|
|
if (k >= "z") return void 0
|
|
|
|
// Return a proxy as property descriptor, so that we can log accesses.
|
|
|
|
return Proxy.create({
|
|
|
|
get: function(r, attr) {
|
|
|
|
descget += attr[0].toUpperCase()
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
has: function(attr) {
|
|
|
|
descget += attr[0]
|
|
|
|
switch (attr) {
|
|
|
|
case "writable":
|
|
|
|
case "enumerable":
|
|
|
|
case "configurable":
|
|
|
|
case "value":
|
|
|
|
return true
|
|
|
|
case "get":
|
|
|
|
case "set":
|
|
|
|
return false
|
|
|
|
default:
|
|
|
|
assertUnreachable()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestHasOwn2(handler, create) {
|
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({
|
|
|
|
hasOwn: function(k) { key = k; return k < "z" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn({
|
|
|
|
hasOwn: function(k) { return this.hasOwn2(k) },
|
|
|
|
hasOwn2: function(k) { key = k; return k < "z" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42} : void 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42} : void 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k; return k < "z" ? {get value() { return 42 }} : void 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn({
|
|
|
|
hasOwn: undefined,
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k; return k < "z" ? {value: 42} : void 0
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwn(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { key = k; return k < "z" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestHasOwnThrow(handler) {
|
|
|
|
TestWithProxies(TestHasOwnThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestHasOwnThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, "a")},
|
|
|
|
"myexn")
|
|
|
|
assertThrows(function(){ Object.prototype.hasOwnProperty.call(p, 99)},
|
|
|
|
"myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
|
|
|
hasOwn: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
|
|
|
hasOwn: function(k) { return this.hasOwn2(k) },
|
|
|
|
hasOwn2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwnThrow({
|
|
|
|
hasOwn: undefined,
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestHasOwnThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestHasOwnThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
|
|
|
|
// Instanceof (instanceof)
|
2011-06-03 10:15:49 +00:00
|
|
|
|
|
|
|
function TestInstanceof() {
|
2011-09-16 13:38:30 +00:00
|
|
|
var o1 = {}
|
2011-06-03 10:15:49 +00:00
|
|
|
var p1 = Proxy.create({})
|
2011-09-16 13:38:30 +00:00
|
|
|
var p2 = Proxy.create({}, o1)
|
2011-06-03 10:15:49 +00:00
|
|
|
var p3 = Proxy.create({}, 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)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertFalse(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)
|
2011-09-13 11:42:57 +00:00
|
|
|
assertTrue(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)
|
2011-09-13 11:42:57 +00:00
|
|
|
assertTrue(p3 instanceof f0)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertFalse(p3 instanceof f1)
|
|
|
|
assertTrue(p3 instanceof f2)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertFalse(p3 instanceof f3)
|
|
|
|
assertTrue(o2 instanceof Object)
|
|
|
|
assertTrue(o2 instanceof f0)
|
|
|
|
assertFalse(o2 instanceof f1)
|
|
|
|
assertTrue(o2 instanceof f2)
|
|
|
|
assertFalse(o2 instanceof f3)
|
2011-09-13 11:42:57 +00:00
|
|
|
|
|
|
|
var f = Proxy.createFunction({}, function() {})
|
|
|
|
assertTrue(f instanceof Function)
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestInstanceof()
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-21 11:20:27 +00:00
|
|
|
// Prototype (Object.getPrototypeOf, Object.prototype.isPrototypeOf).
|
2011-06-03 10:15:49 +00:00
|
|
|
|
|
|
|
function TestPrototype() {
|
2011-09-16 13:38:30 +00:00
|
|
|
var o1 = {}
|
2011-06-03 10:15:49 +00:00
|
|
|
var p1 = Proxy.create({})
|
2011-09-16 13:38:30 +00:00
|
|
|
var p2 = Proxy.create({}, o1)
|
2011-06-03 10:15:49 +00:00
|
|
|
var p3 = Proxy.create({}, p2)
|
|
|
|
var p4 = Proxy.create({}, 666)
|
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)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertSame(Object.getPrototypeOf(p1), null)
|
2011-09-16 13:38:30 +00:00
|
|
|
assertSame(Object.getPrototypeOf(p2), o1)
|
2011-06-03 10:15:49 +00:00
|
|
|
assertSame(Object.getPrototypeOf(p3), p2)
|
|
|
|
assertSame(Object.getPrototypeOf(p4), null)
|
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))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf(p1))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf(p2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf(p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf(p4))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue(Object.prototype.isPrototypeOf(o2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, o1))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p1))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Object.prototype, p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(Object.prototype, p4))
|
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))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(o1, p2))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(o1, p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o1, p4))
|
|
|
|
assertTrue(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))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p1, p4))
|
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))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(p2, p3))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(p2, p4))
|
2011-09-16 13:38:30 +00:00
|
|
|
assertTrue(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, p4))
|
|
|
|
assertFalse(Object.prototype.isPrototypeOf.call(o2, o2))
|
2011-09-13 11:42:57 +00:00
|
|
|
|
|
|
|
var f = Proxy.createFunction({}, function() {})
|
|
|
|
assertSame(Object.getPrototypeOf(f), Function.prototype)
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf(f))
|
|
|
|
assertTrue(Object.prototype.isPrototypeOf.call(Function.prototype, f))
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestPrototype()
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
// Property names (Object.getOwnPropertyNames, Object.keys).
|
2011-06-03 10:15:49 +00:00
|
|
|
|
|
|
|
function TestPropertyNames(names, handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestPropertyNames2, [names, handler])
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestPropertyNames2(names_handler, create) {
|
|
|
|
var p = create(names_handler[1])
|
|
|
|
assertArrayEquals(names_handler[0], Object.getOwnPropertyNames(p))
|
2011-06-03 10:15:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestPropertyNames([], {
|
|
|
|
getOwnPropertyNames: function() { return [] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestPropertyNames(["a", "zz", " ", "0"], {
|
|
|
|
getOwnPropertyNames: function() { return ["a", "zz", " ", 0] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestPropertyNames(["throw", "function "], {
|
|
|
|
getOwnPropertyNames: function() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2: function() { return ["throw", "function "] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-06-03 10:15:49 +00:00
|
|
|
TestPropertyNames(["[object Object]"], {
|
|
|
|
get getOwnPropertyNames() {
|
|
|
|
return function() { return [{}] }
|
|
|
|
}
|
|
|
|
})
|
2011-07-13 11:01:17 +00:00
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestPropertyNamesThrow(handler) {
|
|
|
|
TestWithProxies(TestPropertyNamesThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestPropertyNamesThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.getOwnPropertyNames(p) }, "myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestPropertyNamesThrow({
|
|
|
|
getOwnPropertyNames: function() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestPropertyNamesThrow({
|
|
|
|
getOwnPropertyNames: function() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2: function() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
function TestKeys(names, handler) {
|
2011-09-13 11:42:57 +00:00
|
|
|
TestWithProxies(TestKeys2, [names, handler])
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestKeys2(names_handler, create) {
|
|
|
|
var p = create(names_handler[1])
|
|
|
|
assertArrayEquals(names_handler[0], Object.keys(p))
|
2011-07-13 11:01:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestKeys([], {
|
|
|
|
keys: function() { return [] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["a", "zz", " ", "0"], {
|
|
|
|
keys: function() { return ["a", "zz", " ", 0] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["throw", "function "], {
|
|
|
|
keys: function() { return this.keys2() },
|
|
|
|
keys2: function() { return ["throw", "function "] }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["[object Object]"], {
|
|
|
|
get keys() {
|
|
|
|
return function() { return [{}] }
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["a", "0"], {
|
|
|
|
getOwnPropertyNames: function() { return ["a", 23, "zz", "", 0] },
|
|
|
|
getOwnPropertyDescriptor: function(k) { return {enumerable: k.length == 1} }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["23", "zz", ""], {
|
|
|
|
getOwnPropertyNames: function() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2: function() { return ["a", 23, "zz", "", 0] },
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { return {enumerable: k.length != 1} }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys(["a", "b", "c", "5"], {
|
|
|
|
get getOwnPropertyNames() {
|
|
|
|
return function() { return ["0", 4, "a", "b", "c", 5] }
|
|
|
|
},
|
|
|
|
get getOwnPropertyDescriptor() {
|
|
|
|
return function(k) { return {enumerable: k >= "44"} }
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-13 11:01:17 +00:00
|
|
|
TestKeys([], {
|
|
|
|
get getOwnPropertyNames() {
|
|
|
|
return function() { return ["a", "b", "c"] }
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor: function(k) { return {} }
|
|
|
|
})
|
2011-07-18 13:04:52 +00:00
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestKeysThrow(handler) {
|
|
|
|
TestWithProxies(TestKeysThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestKeysThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.keys(p) }, "myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
keys: function() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
keys: function() { return this.keys2() },
|
|
|
|
keys2: function() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
getOwnPropertyNames: function() { throw "myexn" },
|
|
|
|
getOwnPropertyDescriptor: function(k) { return true }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
getOwnPropertyNames: function() { return [1, 2] },
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
getOwnPropertyNames: function() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2: function() { throw "myexn" },
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
getOwnPropertyNames: function() { return this.getOwnPropertyNames2() },
|
|
|
|
getOwnPropertyNames2: function() { return [1, 2] },
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
get getOwnPropertyNames() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow({
|
|
|
|
get getOwnPropertyNames() {
|
|
|
|
return function() { throw "myexn" }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestKeysThrow([], {
|
|
|
|
get getOwnPropertyNames() {
|
|
|
|
return function() { return [1, 2] }
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor: function(k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2011-07-18 13:04:52 +00:00
|
|
|
|
|
|
|
// Fixing (Object.freeze, Object.seal, Object.preventExtensions,
|
|
|
|
// Object.isFrozen, Object.isSealed, Object.isExtensible)
|
|
|
|
|
|
|
|
function TestFix(names, handler) {
|
|
|
|
var proto = {p: 77}
|
|
|
|
var assertFixing = function(o, s, f, e) {
|
|
|
|
assertEquals(s, Object.isSealed(o))
|
|
|
|
assertEquals(f, Object.isFrozen(o))
|
|
|
|
assertEquals(e, Object.isExtensible(o))
|
|
|
|
}
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
var p1 = Proxy.create(handler, proto)
|
|
|
|
assertFixing(p1, false, false, true)
|
|
|
|
Object.seal(p1)
|
|
|
|
assertFixing(p1, true, names.length === 0, false)
|
|
|
|
assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p1).sort())
|
2011-07-18 13:04:52 +00:00
|
|
|
assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
|
2011-09-13 13:07:20 +00:00
|
|
|
Object.keys(p1).sort())
|
|
|
|
assertEquals(proto, Object.getPrototypeOf(p1))
|
|
|
|
assertEquals(77, p1.p)
|
|
|
|
for (var n in p1) {
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(p1, n)
|
2011-07-18 13:04:52 +00:00
|
|
|
if (desc !== undefined) assertFalse(desc.configurable)
|
|
|
|
}
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
var p2 = Proxy.create(handler, proto)
|
|
|
|
assertFixing(p2, false, false, true)
|
|
|
|
Object.freeze(p2)
|
|
|
|
assertFixing(p2, true, true, false)
|
|
|
|
assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p2).sort())
|
2011-07-18 13:04:52 +00:00
|
|
|
assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
|
2011-09-13 13:07:20 +00:00
|
|
|
Object.keys(p2).sort())
|
|
|
|
assertEquals(proto, Object.getPrototypeOf(p2))
|
|
|
|
assertEquals(77, p2.p)
|
|
|
|
for (var n in p2) {
|
|
|
|
var desc = Object.getOwnPropertyDescriptor(p2, n)
|
2011-07-18 13:04:52 +00:00
|
|
|
if (desc !== undefined) assertFalse(desc.writable)
|
|
|
|
if (desc !== undefined) assertFalse(desc.configurable)
|
|
|
|
}
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
var p3 = Proxy.create(handler, proto)
|
|
|
|
assertFixing(p3, false, false, true)
|
|
|
|
Object.preventExtensions(p3)
|
|
|
|
assertFixing(p3, names.length === 0, names.length === 0, false)
|
|
|
|
assertArrayEquals(names.sort(), Object.getOwnPropertyNames(p3).sort())
|
2011-07-18 13:04:52 +00:00
|
|
|
assertArrayEquals(names.filter(function(x) {return x < "z"}).sort(),
|
2011-09-13 13:07:20 +00:00
|
|
|
Object.keys(p3).sort())
|
|
|
|
assertEquals(proto, Object.getPrototypeOf(p3))
|
|
|
|
assertEquals(77, p3.p)
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
var p = Proxy.create(handler, proto)
|
|
|
|
var o = Object.create(p)
|
|
|
|
assertFixing(p, false, false, true)
|
|
|
|
assertFixing(o, false, false, true)
|
|
|
|
Object.freeze(o)
|
|
|
|
assertFixing(p, false, false, true)
|
|
|
|
assertFixing(o, true, true, false)
|
2011-07-18 13:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TestFix([], {
|
|
|
|
fix: function() { return {} }
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-09-22 10:45:37 +00:00
|
|
|
TestFix(["a", "b", "c", "3", "zz"], {
|
2011-07-18 13:04:52 +00:00
|
|
|
fix: function() {
|
|
|
|
return {
|
|
|
|
a: {value: "a", writable: true, configurable: false, enumerable: true},
|
|
|
|
b: {value: 33, writable: false, configurable: false, enumerable: true},
|
|
|
|
c: {value: 0, writable: true, configurable: true, enumerable: true},
|
2011-09-22 10:45:37 +00:00
|
|
|
'3': {value: true, writable: false, configurable: true, enumerable: true},
|
2011-07-18 13:04:52 +00:00
|
|
|
zz: {value: 0, enumerable: false}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-18 13:04:52 +00:00
|
|
|
TestFix(["a"], {
|
|
|
|
fix: function() { return this.fix2() },
|
|
|
|
fix2: function() {
|
|
|
|
return {a: {value: 4, writable: true, configurable: true, enumerable: true}}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-07-18 13:04:52 +00:00
|
|
|
TestFix(["b"], {
|
|
|
|
get fix() {
|
|
|
|
return function() {
|
|
|
|
return {b: {configurable: true, writable: true, enumerable: true}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2011-07-21 11:20:27 +00:00
|
|
|
|
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
function TestFixFunction(fix) {
|
|
|
|
var f1 = Proxy.createFunction({
|
|
|
|
fix: function() { return {} }
|
|
|
|
}, function() {})
|
|
|
|
fix(f1)
|
|
|
|
assertEquals(0, f1.length)
|
|
|
|
|
|
|
|
var f2 = Proxy.createFunction({
|
|
|
|
fix: function() { return {length: {value: 3}} }
|
|
|
|
}, function() {})
|
|
|
|
fix(f2)
|
|
|
|
assertEquals(3, f2.length)
|
|
|
|
|
|
|
|
var f3 = Proxy.createFunction({
|
|
|
|
fix: function() { return {length: {value: "huh"}} }
|
|
|
|
}, function() {})
|
|
|
|
fix(f3)
|
|
|
|
assertEquals(0, f1.length)
|
|
|
|
}
|
2011-07-21 11:20:27 +00:00
|
|
|
|
2011-09-13 11:42:57 +00:00
|
|
|
TestFixFunction(Object.seal)
|
|
|
|
TestFixFunction(Object.freeze)
|
|
|
|
TestFixFunction(Object.preventExtensions)
|
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestFixThrow(handler) {
|
|
|
|
TestWithProxies(TestFixThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestFixThrow2(handler) {
|
|
|
|
var p = Proxy.create(handler, {})
|
|
|
|
assertThrows(function(){ Object.seal(p) }, "myexn")
|
|
|
|
assertThrows(function(){ Object.freeze(p) }, "myexn")
|
|
|
|
assertThrows(function(){ Object.preventExtensions(p) }, "myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
TestFixThrow({
|
|
|
|
fix: function() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestFixThrow({
|
|
|
|
fix: function() { return this.fix2() },
|
|
|
|
fix2: function() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestFixThrow({
|
|
|
|
get fix() { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestFixThrow({
|
|
|
|
get fix() {
|
|
|
|
return function() { throw "myexn" }
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
|
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) {
|
2011-09-13 13:07:20 +00:00
|
|
|
var p = Proxy.create(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))
|
2011-07-21 11:20:27 +00:00
|
|
|
assertEquals("", 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
|
|
|
|
|
|
|
var f = Proxy.createFunction(handler, function() {})
|
|
|
|
key = ""
|
|
|
|
assertEquals("[object Function]", Object.prototype.toString.call(f))
|
|
|
|
assertEquals("", 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)
|
|
|
|
assertDoesNotThrow(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))
|
|
|
|
assertEquals("", key)
|
|
|
|
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" } }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestToString(Proxy.create({
|
|
|
|
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) {
|
|
|
|
var p = Proxy.create(handler)
|
|
|
|
assertEquals("[object Object]", Object.prototype.toString.call(p))
|
|
|
|
assertThrows(function(){ Object.prototype.toLocaleString.call(p) }, "myexn")
|
|
|
|
|
|
|
|
var f = Proxy.createFunction(handler, function() {})
|
|
|
|
assertEquals("[object Function]", Object.prototype.toString.call(f))
|
|
|
|
assertThrows(function(){ Object.prototype.toLocaleString.call(f) }, "myexn")
|
2011-09-16 13:38:30 +00:00
|
|
|
|
|
|
|
var o = Object.create(p)
|
|
|
|
assertEquals("[object Object]", Object.prototype.toString.call(o))
|
|
|
|
assertThrows(function(){ 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 function() { throw "myexn" } }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestToStringThrow({
|
|
|
|
get: function(r, k) { return this.get2(r, k) },
|
|
|
|
get2: function(r, k) { throw "myexn" }
|
|
|
|
})
|
|
|
|
|
|
|
|
TestToStringThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestToStringThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(r, k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestValueOf2(handler, create) {
|
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({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestIsEnumerable2(handler, create) {
|
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({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k; return {enumerable: k < "z", configurable: true}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerable({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
return this.getOwnPropertyDescriptor2(k)
|
|
|
|
},
|
|
|
|
getOwnPropertyDescriptor2: function(k) {
|
|
|
|
key = k; return {enumerable: k < "z", configurable: true}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerable({
|
|
|
|
getOwnPropertyDescriptor: function(k) {
|
|
|
|
key = k; return {get enumerable() { return k < "z" }, configurable: true}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerable(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) {
|
|
|
|
key = k; return {enumerable: k < "z", configurable: true}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}))
|
2011-09-13 11:42:57 +00:00
|
|
|
|
|
|
|
|
2011-09-13 13:07:20 +00:00
|
|
|
function TestIsEnumerableThrow(handler) {
|
|
|
|
TestWithProxies(TestIsEnumerableThrow2, handler)
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestIsEnumerableThrow2(handler, create) {
|
|
|
|
var p = create(handler)
|
|
|
|
assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, "a") },
|
|
|
|
"myexn")
|
|
|
|
assertThrows(function(){ Object.prototype.propertyIsEnumerable.call(p, 11) },
|
|
|
|
"myexn")
|
|
|
|
}
|
|
|
|
|
|
|
|
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}
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
TestIsEnumerableThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) { throw "myexn" }
|
|
|
|
}))
|
|
|
|
|
|
|
|
TestIsEnumerableThrow(Proxy.create({
|
|
|
|
get: function(pr, pk) {
|
|
|
|
return function(k) { throw "myexn" }
|
|
|
|
}
|
|
|
|
}))
|