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

Side by Side Diff: src/array.js

Issue 7799027: Lock the prototype of internal classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Final commit. Created 9 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/date.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 return current; 1307 return current;
1308 } 1308 }
1309 1309
1310 // ES5, 15.4.3.2 1310 // ES5, 15.4.3.2
1311 function ArrayIsArray(obj) { 1311 function ArrayIsArray(obj) {
1312 return IS_ARRAY(obj); 1312 return IS_ARRAY(obj);
1313 } 1313 }
1314 1314
1315 1315
1316 // ------------------------------------------------------------------- 1316 // -------------------------------------------------------------------
1317 function SetupArray() { 1317 function SetUpArray() {
1318 // Setup non-enumerable constructor property on the Array.prototype 1318 %CheckIsBootstrapping();
1319 // Set up non-enumerable constructor property on the Array.prototype
1319 // object. 1320 // object.
1320 %SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM); 1321 %SetProperty($Array.prototype, "constructor", $Array, DONT_ENUM);
1321 1322
1322 // Setup non-enumerable functions on the Array object. 1323 // Set up non-enumerable functions on the Array object.
1323 InstallFunctions($Array, DONT_ENUM, $Array( 1324 InstallFunctions($Array, DONT_ENUM, $Array(
1324 "isArray", ArrayIsArray 1325 "isArray", ArrayIsArray
1325 )); 1326 ));
1326 1327
1327 var specialFunctions = %SpecialArrayFunctions({}); 1328 var specialFunctions = %SpecialArrayFunctions({});
1328 1329
1329 function getFunction(name, jsBuiltin, len) { 1330 function getFunction(name, jsBuiltin, len) {
1330 var f = jsBuiltin; 1331 var f = jsBuiltin;
1331 if (specialFunctions.hasOwnProperty(name)) { 1332 if (specialFunctions.hasOwnProperty(name)) {
1332 f = specialFunctions[name]; 1333 f = specialFunctions[name];
1333 } 1334 }
1334 if (!IS_UNDEFINED(len)) { 1335 if (!IS_UNDEFINED(len)) {
1335 %FunctionSetLength(f, len); 1336 %FunctionSetLength(f, len);
1336 } 1337 }
1337 return f; 1338 return f;
1338 } 1339 }
1339 1340
1340 // Setup non-enumerable functions of the Array.prototype object and 1341 // Set up non-enumerable functions of the Array.prototype object and
1341 // set their names. 1342 // set their names.
1342 // Manipulate the length of some of the functions to meet 1343 // Manipulate the length of some of the functions to meet
1343 // expectations set by ECMA-262 or Mozilla. 1344 // expectations set by ECMA-262 or Mozilla.
1344 InstallFunctionsOnHiddenPrototype($Array.prototype, DONT_ENUM, $Array( 1345 InstallFunctionsOnHiddenPrototype($Array.prototype, DONT_ENUM, $Array(
1345 "toString", getFunction("toString", ArrayToString), 1346 "toString", getFunction("toString", ArrayToString),
1346 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), 1347 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString),
1347 "join", getFunction("join", ArrayJoin), 1348 "join", getFunction("join", ArrayJoin),
1348 "pop", getFunction("pop", ArrayPop), 1349 "pop", getFunction("pop", ArrayPop),
1349 "push", getFunction("push", ArrayPush, 1), 1350 "push", getFunction("push", ArrayPush, 1),
1350 "concat", getFunction("concat", ArrayConcat, 1), 1351 "concat", getFunction("concat", ArrayConcat, 1),
(...skipping 10 matching lines...) Expand all
1361 "map", getFunction("map", ArrayMap, 1), 1362 "map", getFunction("map", ArrayMap, 1),
1362 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), 1363 "indexOf", getFunction("indexOf", ArrayIndexOf, 1),
1363 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1364 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1364 "reduce", getFunction("reduce", ArrayReduce, 1), 1365 "reduce", getFunction("reduce", ArrayReduce, 1),
1365 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) 1366 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
1366 )); 1367 ));
1367 1368
1368 %FinishArrayPrototypeSetup($Array.prototype); 1369 %FinishArrayPrototypeSetup($Array.prototype);
1369 1370
1370 // The internal Array prototype doesn't need to be fancy, since it's never 1371 // The internal Array prototype doesn't need to be fancy, since it's never
1371 // exposed to user code, so no hidden prototypes or DONT_ENUM attributes 1372 // exposed to user code.
1372 // are necessary. 1373 // Adding only the functions that are actually used.
1373 // The null __proto__ ensures that we never inherit any user created 1374 SetUpLockedPrototype(InternalArray, $Array(), $Array(
1374 // getters or setters from, e.g., Object.prototype. 1375 "join", getFunction("join", ArrayJoin),
1375 InternalArray.prototype.__proto__ = null; 1376 "pop", getFunction("pop", ArrayPop),
1376 // Adding only the functions that are actually used, and a toString. 1377 "push", getFunction("push", ArrayPush)
1377 InternalArray.prototype.join = getFunction("join", ArrayJoin); 1378 ));
1378 InternalArray.prototype.pop = getFunction("pop", ArrayPop);
1379 InternalArray.prototype.push = getFunction("push", ArrayPush);
1380 InternalArray.prototype.toString = function() {
1381 return "Internal Array, length " + this.length;
1382 };
1383 } 1379 }
1384 1380
1385 1381 SetUpArray();
1386 SetupArray();
OLDNEW
« no previous file with comments | « no previous file | src/date.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698