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

Side by Side Diff: extensions/renderer/safe_builtins.cc

Issue 482603002: Unify logic of stack trace generation for extension errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add $Error and $String.indexOf to safe builtins Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "extensions/renderer/safe_builtins.h" 5 #include "extensions/renderer/safe_builtins.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "extensions/renderer/script_context.h" 10 #include "extensions/renderer/script_context.h"
(...skipping 23 matching lines...) Expand all
34 "\n" 34 "\n"
35 "// Used in the callback implementation, could potentially be clobbered.\n" 35 "// Used in the callback implementation, could potentially be clobbered.\n"
36 "function makeCallable(obj, target, isStatic, propertyNames) {\n" 36 "function makeCallable(obj, target, isStatic, propertyNames) {\n"
37 " propertyNames.forEach(function(propertyName) {\n" 37 " propertyNames.forEach(function(propertyName) {\n"
38 " var property = obj[propertyName];\n" 38 " var property = obj[propertyName];\n"
39 " target[propertyName] = function() {\n" 39 " target[propertyName] = function() {\n"
40 " var recv = obj;\n" 40 " var recv = obj;\n"
41 " var firstArgIndex = 0;\n" 41 " var firstArgIndex = 0;\n"
42 " if (!isStatic) {\n" 42 " if (!isStatic) {\n"
43 " if (arguments.length == 0)\n" 43 " if (arguments.length == 0)\n"
44 " throw 'There must be at least one argument, the recevier';\n" 44 " throw 'There must be at least one argument, the receiver';\n"
45 " recv = arguments[0];\n" 45 " recv = arguments[0];\n"
46 " firstArgIndex = 1;\n" 46 " firstArgIndex = 1;\n"
47 " }\n" 47 " }\n"
48 " return Apply(\n" 48 " return Apply(\n"
49 " property, recv, arguments, firstArgIndex, arguments.length);\n" 49 " property, recv, arguments, firstArgIndex, arguments.length);\n"
50 " };\n" 50 " };\n"
51 " });\n" 51 " });\n"
52 "}\n" 52 "}\n"
53 "\n" 53 "\n"
54 "function saveBuiltin(builtin, protoPropertyNames, staticPropertyNames) {\n" 54 "function saveBuiltin(builtin, protoPropertyNames, staticPropertyNames) {\n"
55 " var safe = function() {\n" 55 " var safe = function() {\n"
56 " throw 'Safe objects cannot be called nor constructed. ' +\n" 56 " throw 'Safe objects cannot be called nor constructed. ' +\n"
57 " 'Use $Foo.self() or new $Foo.self() instead.';\n" 57 " 'Use $Foo.self() or new $Foo.self() instead.';\n"
58 " };\n" 58 " };\n"
59 " safe.self = builtin;\n" 59 " safe.self = builtin;\n"
60 " makeCallable(builtin.prototype, safe, false, protoPropertyNames);\n" 60 " makeCallable(builtin.prototype, safe, false, protoPropertyNames);\n"
61 " if (staticPropertyNames)\n" 61 " if (staticPropertyNames)\n"
62 " makeCallable(builtin, safe, true, staticPropertyNames);\n" 62 " makeCallable(builtin, safe, true, staticPropertyNames);\n"
63 " Save(builtin.name, safe);\n" 63 " Save(builtin.name, safe);\n"
64 "}\n" 64 "}\n"
65 "\n" 65 "\n"
66 "// Save only what is needed to make tests that override builtins pass.\n" 66 "// Save only what is needed by the extension modules.\n"
67 "saveBuiltin(Object,\n" 67 "saveBuiltin(Object,\n"
68 " ['hasOwnProperty'],\n" 68 " ['hasOwnProperty'],\n"
69 " ['create', 'defineProperty', 'getOwnPropertyDescriptor',\n" 69 " ['create', 'defineProperty', 'getOwnPropertyDescriptor',\n"
70 " 'getPrototypeOf', 'keys']);\n" 70 " 'getPrototypeOf', 'keys']);\n"
71 "saveBuiltin(Function,\n" 71 "saveBuiltin(Function,\n"
72 " ['apply', 'bind', 'call']);\n" 72 " ['apply', 'bind', 'call']);\n"
73 "saveBuiltin(Array,\n" 73 "saveBuiltin(Array,\n"
74 " ['concat', 'forEach', 'indexOf', 'join', 'push', 'slice',\n" 74 " ['concat', 'forEach', 'indexOf', 'join', 'push', 'slice',\n"
75 " 'splice', 'map', 'filter']);\n" 75 " 'splice', 'map', 'filter']);\n"
76 "saveBuiltin(String,\n" 76 "saveBuiltin(String,\n"
77 " ['slice', 'split']);\n" 77 " ['indexOf', 'slice', 'split']);\n"
78 "saveBuiltin(RegExp,\n" 78 "saveBuiltin(RegExp,\n"
79 " ['test']);\n" 79 " ['test']);\n"
80 "saveBuiltin(Error,\n"
81 " [],\n"
82 " ['captureStackTrace']);\n"
80 "\n" 83 "\n"
81 "// JSON is trickier because extensions can override toJSON in\n" 84 "// JSON is trickier because extensions can override toJSON in\n"
82 "// incompatible ways, and we need to prevent that.\n" 85 "// incompatible ways, and we need to prevent that.\n"
83 "var builtinTypes = [\n" 86 "var builtinTypes = [\n"
84 " Object, Function, Array, String, Boolean, Number, Date, RegExp\n" 87 " Object, Function, Array, String, Boolean, Number, Date, RegExp\n"
85 "];\n" 88 "];\n"
86 "var builtinToJSONs = builtinTypes.map(function(t) {\n" 89 "var builtinToJSONs = builtinTypes.map(function(t) {\n"
87 " return t.toJSON;\n" 90 " return t.toJSON;\n"
88 "});\n" 91 "});\n"
89 "var builtinArray = Array;\n" 92 "var builtinArray = Array;\n"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 226 }
224 227
225 v8::Local<v8::Object> SafeBuiltins::GetRegExp() const { 228 v8::Local<v8::Object> SafeBuiltins::GetRegExp() const {
226 return Load("RegExp", context_->v8_context()); 229 return Load("RegExp", context_->v8_context());
227 } 230 }
228 231
229 v8::Local<v8::Object> SafeBuiltins::GetString() const { 232 v8::Local<v8::Object> SafeBuiltins::GetString() const {
230 return Load("String", context_->v8_context()); 233 return Load("String", context_->v8_context());
231 } 234 }
232 235
236 v8::Local<v8::Object> SafeBuiltins::GetError() const {
237 return Load("Error", context_->v8_context());
238 }
239
233 } // namespace extensions 240 } // namespace extensions
OLDNEW
« extensions/renderer/resources/utils.js ('K') | « extensions/renderer/safe_builtins.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698