OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function() { | 5 (function() { |
6 | 6 |
7 // We are going to kill all of the builtins, so hold onto the ones we need. | 7 // We are going to kill all of the builtins, so hold onto the ones we need. |
8 var defineGetter = Object.prototype.__defineGetter__; | 8 var defineGetter = Object.prototype.__defineGetter__; |
9 var defineSetter = Object.prototype.__defineSetter__; | 9 var defineSetter = Object.prototype.__defineSetter__; |
10 var Error = window.Error; | 10 var Error = window.Error; |
11 var forEach = Array.prototype.forEach; | 11 var forEach = Array.prototype.forEach; |
12 var push = Array.prototype.push; | 12 var push = Array.prototype.push; |
13 var hasOwnProperty = Object.prototype.hasOwnProperty; | 13 var hasOwnProperty = Object.prototype.hasOwnProperty; |
14 var getOwnPropertyNames = Object.getOwnPropertyNames; | 14 var getOwnPropertyNames = Object.getOwnPropertyNames; |
15 var stringify = JSON.stringify; | 15 var stringify = JSON.stringify; |
16 | 16 |
17 // Kill all of the builtins functions to give us a fairly high confidence that | 17 // Kill all of the builtins functions to give us a fairly high confidence that |
18 // the environment our bindings run in can't interfere with our code. | 18 // the environment our bindings run in can't interfere with our code. |
19 // These are taken from the ECMAScript spec. | 19 // These are taken from the ECMAScript spec. |
20 var builtinTypes = [ | 20 var builtinTypes = [ |
21 Object, Function, Array, String, Boolean, Number, Math, Date, RegExp, JSON, | 21 Object, Function, Array, String, Boolean, Number, Math, Date, RegExp, JSON, |
22 ]; | 22 ]; |
23 | 23 |
24 function clobber(obj, name, qualifiedName) { | 24 function clobber(obj, name, qualifiedName) { |
25 // Clobbering constructors would break everything. | 25 // Clobbering constructors would break everything. |
26 // Clobbering toString is annoying. | 26 // Clobbering toString is annoying. |
27 // Clobbering __proto__ breaks in ways that grep can't find. | 27 // Clobbering __proto__ breaks in ways that grep can't find. |
| 28 // Clobbering function name will break because |
| 29 // SafeBuiltins does not support getters yet. See crbug.com/463526. |
28 // Clobbering Function.call would make it impossible to implement these tests. | 30 // Clobbering Function.call would make it impossible to implement these tests. |
29 // Clobbering Object.valueOf breaks v8. | 31 // Clobbering Object.valueOf breaks v8. |
30 if (name == 'constructor' || | 32 if (name == 'constructor' || |
31 name == 'toString' || | 33 name == 'toString' || |
32 name == '__proto__' || | 34 name == '__proto__' || |
| 35 name == 'name' && typeof obj == 'function' || |
33 qualifiedName == 'Function.call' || | 36 qualifiedName == 'Function.call' || |
34 qualifiedName == 'Object.valueOf') { | 37 qualifiedName == 'Object.valueOf') { |
35 return; | 38 return; |
36 } | 39 } |
37 if (typeof(obj[name]) == 'function') { | 40 if (typeof obj[name] == 'function') { |
38 obj[name] = function() { | 41 obj[name] = function() { |
39 throw new Error('Clobbered ' + qualifiedName + ' function'); | 42 throw new Error('Clobbered ' + qualifiedName + ' function'); |
40 }; | 43 }; |
41 } else { | 44 } else { |
42 defineGetter.call(obj, name, function() { | 45 defineGetter.call(obj, name, function() { |
43 throw new Error('Clobbered ' + qualifiedName + ' getter'); | 46 throw new Error('Clobbered ' + qualifiedName + ' getter'); |
44 }); | 47 }); |
45 } | 48 } |
46 } | 49 } |
47 | 50 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 if (!message) | 294 if (!message) |
292 message = kMessage; | 295 message = kMessage; |
293 | 296 |
294 chrome.runtime.sendMessage(extensionId, message, | 297 chrome.runtime.sendMessage(extensionId, message, |
295 {'includeTlsChannelId': includeTlsChannelId}, | 298 {'includeTlsChannelId': includeTlsChannelId}, |
296 checkTlsChannelIdResponse); | 299 checkTlsChannelIdResponse); |
297 } | 300 } |
298 }; | 301 }; |
299 | 302 |
300 }()); | 303 }()); |
OLD | NEW |