Reviewers: mike_bocoup.com,
Message:
that should do it
Description:
[es6] throw TypeError when setting cyclic prototype value
Object.setPrototypeOf() throws a TypeError if value would create a
cycle.
BUG=v8:4197
[email protected]
LOG=N
Please review this at https://codereview.chromium.org/1198523002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+20, -1 lines):
M src/objects.cc
M test/mjsunit/harmony/set-prototype-of.js
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index
44b3721b1a67738546aaf2416a6331113d2f8cd5..cb74ef106c5f7b8d86ada38b45eb79e10025b18b
100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -12402,7 +12402,8 @@ MaybeHandle<Object>
JSObject::SetPrototype(Handle<JSObject> object,
!iter.IsAtEnd(); iter.Advance()) {
if (JSReceiver::cast(iter.GetCurrent()) == *object) {
// Cycle detected.
- THROW_NEW_ERROR(isolate, NewError(MessageTemplate::kCyclicProto),
Object);
+ THROW_NEW_ERROR(isolate, NewTypeError(MessageTemplate::kCyclicProto),
+ Object);
}
}
Index: test/mjsunit/harmony/set-prototype-of.js
diff --git a/test/mjsunit/harmony/set-prototype-of.js
b/test/mjsunit/harmony/set-prototype-of.js
index
e06215a0edfcca65a84b4524f017c9805e856d22..c786f5420f93648475e367ac08bcddab064824c0
100644
--- a/test/mjsunit/harmony/set-prototype-of.js
+++ b/test/mjsunit/harmony/set-prototype-of.js
@@ -139,6 +139,24 @@ function TestSetPrototypeOfNonExtensibleObject() {
TestSetPrototypeOfNonExtensibleObject();
+function TestSetPrototypeCyclic() {
+ var objects = [
+ Object.prototype, {},
+ Array.prototype, [],
+ Error.prototype, new TypeError,
+ // etc ...
+ ];
+ for (var i = 0; i < objects.length; i += 2) {
+ var object = objects[i];
+ var value = objects[i+1];
+ assertThrows(function() {
+ Object.setPrototypeOf(object, value);
+ }, TypeError);
+ }
+}
+TestSetPrototypeCyclic();
+
+
function TestLookup() {
var object = {};
assertFalse('x' in object);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.