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

Side by Side Diff: src/v8natives.js

Issue 7799027: Lock the prototype of internal classes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 %SetNativeFlag(f); 59 %SetNativeFlag(f);
60 } 60 }
61 %ToFastProperties(object); 61 %ToFastProperties(object);
62 } 62 }
63 63
64 // Emulates JSC by installing functions on a hidden prototype that 64 // Emulates JSC by installing functions on a hidden prototype that
65 // lies above the current object/prototype. This lets you override 65 // lies above the current object/prototype. This lets you override
66 // functions on String.prototype etc. and then restore the old function 66 // functions on String.prototype etc. and then restore the old function
67 // with delete. See http://code.google.com/p/chromium/issues/detail?id=1717 67 // with delete. See http://code.google.com/p/chromium/issues/detail?id=1717
68 function InstallFunctionsOnHiddenPrototype(object, attributes, functions) { 68 function InstallFunctionsOnHiddenPrototype(object, attributes, functions) {
69 %AssertIsBootstrapping();
69 var hidden_prototype = new $Object(); 70 var hidden_prototype = new $Object();
70 %SetHiddenPrototype(object, hidden_prototype); 71 %SetHiddenPrototype(object, hidden_prototype);
71 InstallFunctions(hidden_prototype, attributes, functions); 72 InstallFunctions(hidden_prototype, attributes, functions);
72 } 73 }
73 74
74 75
76 // Prevents changes to the prototype of a built-infunction.
77 // The "prototype" property of the function object is made non-configurable,
78 // and the prototype object is made non-extensible. The latter prevents
79 // changing the __proto__ property.
80 function SetupLockedPrototype(constructor, fields, methods) {
81 %AssertIsBootstrapping();
82 var prototype = constructor.prototype;
83 // Install functions first, because this function is used to initialize
84 // PropertyDescriptor itself.
85 InstallFunctions(prototype, DONT_DELETE | DONT_ENUM | READ_ONLY, methods);
86 if (fields) {
87 for (var i = 0; i < fields.length; i++) {
88 %SetProperty(prototype, fields[i], void 0, DONT_ENUM | DONT_DELETE);
89 }
90 }
91 var desc = GetOwnProperty(constructor, "prototype");
92 desc.setWritable(false);
93 desc.setConfigurable(false);
94 DefineOwnProperty(constructor, "prototype", desc, false);
95 prototype.__proto__ = null;
96 %PreventExtensions(prototype);
97 }
98
99
75 // ---------------------------------------------------------------------------- 100 // ----------------------------------------------------------------------------
76 101
77 102
78 // ECMA 262 - 15.1.4 103 // ECMA 262 - 15.1.4
79 function GlobalIsNaN(number) { 104 function GlobalIsNaN(number) {
80 var n = ToNumber(number); 105 var n = ToNumber(number);
81 return NUMBER_IS_NAN(n); 106 return NUMBER_IS_NAN(n);
82 } 107 }
83 108
84 109
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 var f = %CompileString(x); 178 var f = %CompileString(x);
154 if (!IS_FUNCTION(f)) return f; 179 if (!IS_FUNCTION(f)) return f;
155 180
156 return %_CallFunction(receiver, f); 181 return %_CallFunction(receiver, f);
157 } 182 }
158 183
159 184
160 // ---------------------------------------------------------------------------- 185 // ----------------------------------------------------------------------------
161 186
162 187
163 function SetupGlobal() { 188 function SetupGlobal() {
Erik Corry 2011/08/31 05:46:04 SetUpGlobal
189 %AssertIsBootstrapping();
164 // ECMA 262 - 15.1.1.1. 190 // ECMA 262 - 15.1.1.1.
165 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE); 191 %SetProperty(global, "NaN", $NaN, DONT_ENUM | DONT_DELETE);
166 192
167 // ECMA-262 - 15.1.1.2. 193 // ECMA-262 - 15.1.1.2.
168 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE); 194 %SetProperty(global, "Infinity", 1/0, DONT_ENUM | DONT_DELETE);
169 195
170 // ECMA-262 - 15.1.1.3. 196 // ECMA-262 - 15.1.1.3.
171 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE); 197 %SetProperty(global, "undefined", void 0, DONT_ENUM | DONT_DELETE);
172 198
173 // Setup non-enumerable function on the global object. 199 // Setup non-enumerable function on the global object.
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 this.enumerable_ = false; 497 this.enumerable_ = false;
472 this.hasEnumerable_ = false; 498 this.hasEnumerable_ = false;
473 this.configurable_ = false; 499 this.configurable_ = false;
474 this.hasConfigurable_ = false; 500 this.hasConfigurable_ = false;
475 this.get_ = void 0; 501 this.get_ = void 0;
476 this.hasGetter_ = false; 502 this.hasGetter_ = false;
477 this.set_ = void 0; 503 this.set_ = void 0;
478 this.hasSetter_ = false; 504 this.hasSetter_ = false;
479 } 505 }
480 506
481 PropertyDescriptor.prototype.__proto__ = null; 507 SetupLockedPrototype(PropertyDescriptor, $Array(
Erik Corry 2011/08/31 05:46:04 SetUpLockedPrototype
482 508 "value_",
483 PropertyDescriptor.prototype.toString = function() { 509 "hasValue_",
484 return "[object PropertyDescriptor]"; 510 "writable_",
485 }; 511 "hasWritable_",
486 512 "enumerable_",
487 PropertyDescriptor.prototype.setValue = function(value) { 513 "hasEnumerable_",
488 this.value_ = value; 514 "configurable_",
489 this.hasValue_ = true; 515 "hasConfigurable_",
490 } 516 "get_",
491 517 "hasGetter_",
492 518 "set_",
493 PropertyDescriptor.prototype.getValue = function() { 519 "hasSetter_"
494 return this.value_; 520 ), $Array(
495 } 521 "toString", function() {
496 522 return "[object PropertyDescriptor]";
497 523 },
498 PropertyDescriptor.prototype.hasValue = function() { 524 "setValue", function(value) {
499 return this.hasValue_; 525 this.value_ = value;
500 } 526 this.hasValue_ = true;
501 527 },
502 528 "getValue", function() {
503 PropertyDescriptor.prototype.setEnumerable = function(enumerable) { 529 return this.value_;
504 this.enumerable_ = enumerable; 530 },
505 this.hasEnumerable_ = true; 531 "hasValue", function() {
506 } 532 return this.hasValue_;
507 533 },
508 534 "setEnumerable", function(enumerable) {
509 PropertyDescriptor.prototype.isEnumerable = function () { 535 this.enumerable_ = enumerable;
510 return this.enumerable_; 536 this.hasEnumerable_ = true;
511 } 537 },
512 538 "isEnumerable", function () {
513 539 return this.enumerable_;
514 PropertyDescriptor.prototype.hasEnumerable = function() { 540 },
515 return this.hasEnumerable_; 541 "hasEnumerable", function() {
516 } 542 return this.hasEnumerable_;
517 543 },
518 544 "setWritable", function(writable) {
519 PropertyDescriptor.prototype.setWritable = function(writable) { 545 this.writable_ = writable;
520 this.writable_ = writable; 546 this.hasWritable_ = true;
521 this.hasWritable_ = true; 547 },
522 } 548 "isWritable", function() {
523 549 return this.writable_;
524 550 },
525 PropertyDescriptor.prototype.isWritable = function() { 551 "hasWritable", function() {
526 return this.writable_; 552 return this.hasWritable_;
527 } 553 },
528 554 "setConfigurable", function(configurable) {
529 555 this.configurable_ = configurable;
530 PropertyDescriptor.prototype.hasWritable = function() { 556 this.hasConfigurable_ = true;
531 return this.hasWritable_; 557 },
532 } 558 "hasConfigurable", function() {
533 559 return this.hasConfigurable_;
534 560 },
535 PropertyDescriptor.prototype.setConfigurable = function(configurable) { 561 "isConfigurable", function() {
536 this.configurable_ = configurable; 562 return this.configurable_;
537 this.hasConfigurable_ = true; 563 },
538 } 564 "setGet", function(get) {
539 565 this.get_ = get;
540 566 this.hasGetter_ = true;
541 PropertyDescriptor.prototype.hasConfigurable = function() { 567 },
542 return this.hasConfigurable_; 568 "getGet", function() {
543 } 569 return this.get_;
544 570 },
545 571 "hasGetter", function() {
546 PropertyDescriptor.prototype.isConfigurable = function() { 572 return this.hasGetter_;
547 return this.configurable_; 573 },
548 } 574 "setSet", function(set) {
549 575 this.set_ = set;
550 576 this.hasSetter_ = true;
551 PropertyDescriptor.prototype.setGet = function(get) { 577 },
552 this.get_ = get; 578 "getSet", function() {
553 this.hasGetter_ = true; 579 return this.set_;
554 } 580 },
555 581 "hasSetter", function() {
556 582 return this.hasSetter_;
557 PropertyDescriptor.prototype.getGet = function() { 583 }));
558 return this.get_;
559 }
560
561
562 PropertyDescriptor.prototype.hasGetter = function() {
563 return this.hasGetter_;
564 }
565
566
567 PropertyDescriptor.prototype.setSet = function(set) {
568 this.set_ = set;
569 this.hasSetter_ = true;
570 }
571
572
573 PropertyDescriptor.prototype.getSet = function() {
574 return this.set_;
575 }
576
577
578 PropertyDescriptor.prototype.hasSetter = function() {
579 return this.hasSetter_;
580 }
581 584
582 585
583 // Converts an array returned from Runtime_GetOwnProperty to an actual 586 // Converts an array returned from Runtime_GetOwnProperty to an actual
584 // property descriptor. For a description of the array layout please 587 // property descriptor. For a description of the array layout please
585 // see the runtime.cc file. 588 // see the runtime.cc file.
586 function ConvertDescriptorArrayToDescriptor(desc_array) { 589 function ConvertDescriptorArrayToDescriptor(desc_array) {
587 if (desc_array === false) { 590 if (desc_array === false) {
588 throw 'Internal error: invalid desc_array'; 591 throw 'Internal error: invalid desc_array';
589 } 592 }
590 593
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 if (x == null) return { }; 1163 if (x == null) return { };
1161 return ToObject(x); 1164 return ToObject(x);
1162 } 1165 }
1163 }); 1166 });
1164 1167
1165 %SetExpectedNumberOfProperties($Object, 4); 1168 %SetExpectedNumberOfProperties($Object, 4);
1166 1169
1167 // ---------------------------------------------------------------------------- 1170 // ----------------------------------------------------------------------------
1168 1171
1169 1172
1170 function SetupObject() { 1173 function SetupObject() {
Erik Corry 2011/08/31 05:46:04 SetUpObject
1174 %AssertIsBootstrapping();
1171 // Setup non-enumerable functions on the Object.prototype object. 1175 // Setup non-enumerable functions on the Object.prototype object.
1172 InstallFunctions($Object.prototype, DONT_ENUM, $Array( 1176 InstallFunctions($Object.prototype, DONT_ENUM, $Array(
1173 "toString", ObjectToString, 1177 "toString", ObjectToString,
1174 "toLocaleString", ObjectToLocaleString, 1178 "toLocaleString", ObjectToLocaleString,
1175 "valueOf", ObjectValueOf, 1179 "valueOf", ObjectValueOf,
1176 "hasOwnProperty", ObjectHasOwnProperty, 1180 "hasOwnProperty", ObjectHasOwnProperty,
1177 "isPrototypeOf", ObjectIsPrototypeOf, 1181 "isPrototypeOf", ObjectIsPrototypeOf,
1178 "propertyIsEnumerable", ObjectPropertyIsEnumerable, 1182 "propertyIsEnumerable", ObjectPropertyIsEnumerable,
1179 "__defineGetter__", ObjectDefineGetter, 1183 "__defineGetter__", ObjectDefineGetter,
1180 "__lookupGetter__", ObjectLookupGetter, 1184 "__lookupGetter__", ObjectLookupGetter,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 // 'this'. This is not as dictated by ECMA-262. 1227 // 'this'. This is not as dictated by ECMA-262.
1224 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this)) 1228 if (!IS_BOOLEAN(this) && !IS_BOOLEAN_WRAPPER(this))
1225 throw new $TypeError('Boolean.prototype.valueOf is not generic'); 1229 throw new $TypeError('Boolean.prototype.valueOf is not generic');
1226 return %_ValueOf(this); 1230 return %_ValueOf(this);
1227 } 1231 }
1228 1232
1229 1233
1230 // ---------------------------------------------------------------------------- 1234 // ----------------------------------------------------------------------------
1231 1235
1232 1236
1233 function SetupBoolean() { 1237 function SetupBoolean() {
Erik Corry 2011/08/31 05:46:04 SetUpBoolean
1238 %AssertIsBootstrapping();
1234 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array( 1239 InstallFunctions($Boolean.prototype, DONT_ENUM, $Array(
1235 "toString", BooleanToString, 1240 "toString", BooleanToString,
1236 "valueOf", BooleanValueOf 1241 "valueOf", BooleanValueOf
1237 )); 1242 ));
1238 } 1243 }
1239 1244
1240 SetupBoolean(); 1245 SetupBoolean();
1241 1246
1242 // ---------------------------------------------------------------------------- 1247 // ----------------------------------------------------------------------------
1243 // Number 1248 // Number
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 throw new $RangeError("toPrecision() argument must be between 1 and 21"); 1350 throw new $RangeError("toPrecision() argument must be between 1 and 21");
1346 } 1351 }
1347 var x = ToNumber(this); 1352 var x = ToNumber(this);
1348 return %NumberToPrecision(x, p); 1353 return %NumberToPrecision(x, p);
1349 } 1354 }
1350 1355
1351 1356
1352 // ---------------------------------------------------------------------------- 1357 // ----------------------------------------------------------------------------
1353 1358
1354 function SetupNumber() { 1359 function SetupNumber() {
1360 %AssertIsBootstrapping();
Erik Corry 2011/08/31 05:46:04 SetUpNumber
1355 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); 1361 %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8);
1356 // Setup the constructor property on the Number prototype object. 1362 // Setup the constructor property on the Number prototype object.
1357 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); 1363 %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM);
1358 1364
1359 %OptimizeObjectForAddingMultipleProperties($Number, 5); 1365 %OptimizeObjectForAddingMultipleProperties($Number, 5);
1360 // ECMA-262 section 15.7.3.1. 1366 // ECMA-262 section 15.7.3.1.
1361 %SetProperty($Number, 1367 %SetProperty($Number,
1362 "MAX_VALUE", 1368 "MAX_VALUE",
1363 1.7976931348623157e+308, 1369 1.7976931348623157e+308,
1364 DONT_ENUM | DONT_DELETE | READ_ONLY); 1370 DONT_ENUM | DONT_DELETE | READ_ONLY);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 var f = %CompileString(source)(); 1522 var f = %CompileString(source)();
1517 %FunctionMarkNameShouldPrintAsAnonymous(f); 1523 %FunctionMarkNameShouldPrintAsAnonymous(f);
1518 return %SetNewFunctionAttributes(f); 1524 return %SetNewFunctionAttributes(f);
1519 } 1525 }
1520 1526
1521 %SetCode($Function, NewFunction); 1527 %SetCode($Function, NewFunction);
1522 1528
1523 // ---------------------------------------------------------------------------- 1529 // ----------------------------------------------------------------------------
1524 1530
1525 function SetupFunction() { 1531 function SetupFunction() {
1532 %AssertIsBootstrapping();
Erik Corry 2011/08/31 05:46:04 SetUpFunction
1526 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1533 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1527 "bind", FunctionBind, 1534 "bind", FunctionBind,
1528 "toString", FunctionToString 1535 "toString", FunctionToString
1529 )); 1536 ));
1530 } 1537 }
1531 1538
1532 SetupFunction(); 1539 SetupFunction();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698