Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: test/mjsunit/undeletable-functions.js

Issue 100335: Fix http://code.google.com/p/chromium/issues/detail?id=1717... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/undeletable-functions.js
===================================================================
--- test/mjsunit/undeletable-functions.js (revision 0)
+++ test/mjsunit/undeletable-functions.js (revision 0)
@@ -0,0 +1,144 @@
+var array;
Mads Ager (chromium) 2009/05/04 12:20:31 Copyright header and a description of the "problem
+
+array = [
+ "toString", "toLocaleString", "join", "pop", "push", "concat", "reverse",
+ "shift", "unshift", "slice", "splice", "sort", "filter", "forEach", "some",
+ "every", "map", "indexOf", "lastIndexOf", "reduce", "reduceRight"];
+CheckJSCSemantics(Array.prototype, array, "Array prototype");
+
+array = [
+ "toString", "toDateString", "toTimeString", "toLocaleString",
+ "toLocaleDateString", "toLocaleTimeString", "valueOf", "getTime",
+ "getFullYear", "getUTCFullYear", "getMonth", "getUTCMonth", "getDate",
+ "getUTCDate", "getDay", "getUTCDay", "getHours", "getUTCHours", "getMinutes",
+ "getUTCMinutes", "getSeconds", "getUTCSeconds", "getMilliseconds",
+ "getUTCMilliseconds", "getTimezoneOffset", "setTime", "setMilliseconds",
+ "setUTCMilliseconds", "setSeconds", "setUTCSeconds", "setMinutes",
+ "setUTCMinutes", "setHours", "setUTCHours", "setDate", "setUTCDate",
+ "setMonth", "setUTCMonth", "setFullYear", "setUTCFullYear", "toGMTString",
+ "toUTCString", "getYear", "setYear", "toISOString", "toJSON"];
+CheckJSCSemantics(Date.prototype, array, "Date prototype");
+
+array = [
+ "random", "abs", "acos", "asin", "atan", "ceil", "cos", "exp", "floor", "log",
+ "round", "sin", "sqrt", "tan", "atan2", "pow", "max", "min"];
+CheckJSCSemantics(Math, array, "Math1");
+
+CheckEcmaSemantics(Date, ["UTC", "parse", "now"], "Date");
+
+array = [
+ "E", "LN10", "LN2", "LOG2E", "LOG10E", "PI", "SQRT1_2", "SQRT2"];
+CheckDontDelete(Math, array, "Math2");
+
+array = [
+ "escape", "unescape", "decodeURI", "decodeURIComponent", "encodeURI",
+ "encodeURIComponent", "isNaN", "isFinite", "parseInt", "parseFloat", "eval",
+ "execScript"];
+CheckEcmaSemantics(this, array, "Global");
+CheckReadOnlyAttr(this, "Infinity");
+
+array = ["exec", "test", "toString", "compile"];
+CheckEcmaSemantics(RegExp.prototype, array, "RegExp prototype");
+
+array = [
+ "toString", "toLocaleString", "valueOf",
+ //"hasOwnProperty",
+ "isPrototypeOf", "propertyIsEnumerable", "__defineGetter__",
+ "__lookupGetter__", "__defineSetter__", "__lookupSetter__"];
+CheckEcmaSemantics(Object.prototype, array, "Object prototype");
+
+array = [
+ "toString", "valueOf", "toJSON"];
+CheckEcmaSemantics(Boolean.prototype, array, "Boolean prototype");
+
+array = [
+ "toString", "toLocaleString", "valueOf", "toFixed", "toExponential",
+ "toPrecision", "toJSON"];
+CheckEcmaSemantics(Number.prototype, array, "Number prototype");
+
+CheckEcmaSemantics(Function.prototype, ["toString"], "Function prototype");
+
+array = [
+ "charAt", "charCodeAt", "concat", "indexOf",
+ "lastIndexOf", "localeCompare", "match", "replace", "search", "slice",
+ "split", "substring", "substr", "toLowerCase", "toLocaleLowerCase",
+ "toUpperCase", "toLocaleUpperCase", "link", "anchor", "fontcolor", "fontsize",
+ "big", "blink", "bold", "fixed", "italics", "small", "strike", "sub", "sup",
+ "toJSON", "toString", "valueOf"];
+CheckJSCSemantics(String.prototype, array, "String prototype");
+CheckEcmaSemantics(String, ["fromCharCode"], "String");
+
+
+function CheckEcmaSemantics(type, props, name) {
+ print(name);
+ for (var i = 0; i < props.length; i++) {
+ CheckDeletable(type, props[i]);
+ }
+}
+
+
+function CheckJSCSemantics(type, props, name) {
+ print(name);
+ for (var i = 0; i < props.length; i++) {
+ CheckNotDeletable(type, props[i]);
+ }
+}
+
+
+function CheckDontDelete(type, props, name) {
+ print(name);
+ for (var i = 0; i < props.length; i++) {
+ CheckDontDeleteAttr(type, props[i]);
+ }
+}
+
+
+function CheckDeletable(type, prop) {
+ var old = type[prop];
+ if (!type[prop]) return;
+ assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
+ var deleted = delete type[prop];
+ assertTrue(deleted, "delete operator returned false: " + prop);
+ assertFalse(type.hasOwnProperty(prop), "still there after delete: " + prop);
+ type[prop] = "foo";
+ assertEquals("foo", type[prop], "not overwritable: " + prop);
+}
+
+
+function CheckNotDeletable(type, prop) {
+ var old = type[prop];
+ if (!type[prop]) return;
+ assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
+ var deleted = delete type[prop];
+ // Comment this next line to pass the test on JSC:
+ assertFalse(deleted, "delete operator returned true: " + prop);
+ assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
+ type[prop] = "foo";
+ assertEquals("foo", type[prop], "not overwritable: " + prop);
+}
+
+
+function CheckDontDeleteAttr(type, prop) {
+ var old = type[prop];
+ if (!type[prop]) return;
+ assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
+ var deleted = delete type[prop];
+ assertFalse(deleted, "delete operator returned true: " + prop);
+ assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
+ type[prop] = "foo";
+ assertFalse("foo" == type[prop], "overwritable: " + prop);
+}
+
+
+function CheckReadOnlyAttr(type, prop) {
+ var old = type[prop];
+ if (!type[prop]) return;
+ assertTrue(type.hasOwnProperty(prop), "inherited: " + prop);
+ var deleted = delete type[prop];
+ assertFalse(deleted, "delete operator returned true: " + prop);
+ assertTrue(type.hasOwnProperty(prop), "not there after delete: " + prop);
+ type[prop] = "foo";
+ assertEquals("foo", type[prop], "overwritable: " + prop);
+}
+
+print("OK");
« no previous file with comments | « src/string.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698