OLD | NEW |
---|---|
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 var Event = require('event_bindings').Event; | 5 var Event = require('event_bindings').Event; |
6 var forEach = require('utils').forEach; | 6 var forEach = require('utils').forEach; |
7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw | 7 // Note: Beware sneaky getters/setters when using GetAvailbility(). Use safe/raw |
8 // variables as arguments. | 8 // variables as arguments. |
9 var GetAvailability = requireNative('v8_context').GetAvailability; | 9 var GetAvailability = requireNative('v8_context').GetAvailability; |
10 var exceptionHandler = require('uncaught_exception_handler'); | 10 var exceptionHandler = require('uncaught_exception_handler'); |
11 var lastError = require('lastError'); | 11 var lastError = require('lastError'); |
12 var logActivity = requireNative('activityLogger'); | 12 var logActivity = requireNative('activityLogger'); |
13 var logging = requireNative('logging'); | 13 var logging = requireNative('logging'); |
14 var process = requireNative('process'); | 14 var process = requireNative('process'); |
15 var schemaRegistry = requireNative('schema_registry'); | 15 var schemaRegistry = requireNative('schema_registry'); |
16 var schemaUtils = require('schemaUtils'); | 16 var schemaUtils = require('schemaUtils'); |
17 var utils = require('utils'); | 17 var utils = require('utils'); |
18 var sendRequestHandler = require('sendRequest'); | 18 var sendRequestHandler = require('sendRequest'); |
19 | 19 |
20 var contextType = process.GetContextType(); | 20 var contextType = process.GetContextType(); |
21 var extensionId = process.GetExtensionId(); | 21 var extensionId = process.GetExtensionId(); |
22 var manifestVersion = process.GetManifestVersion(); | 22 var manifestVersion = process.GetManifestVersion(); |
23 var sendRequest = sendRequestHandler.sendRequest; | 23 var sendRequest = sendRequestHandler.sendRequest; |
24 | 24 |
25 // Stores the name and definition of each API function, with methods to | 25 // Stores the name and definition of each API function, with methods to |
26 // modify their behaviour (such as a custom way to handle requests to the | 26 // modify their behaviour (such as a custom way to handle requests to the |
27 // API, a custom callback, etc). | 27 // API, a custom callback, etc). |
28 function APIFunctions(namespace) { | 28 function APIFunctions(namespace) { |
29 this.apiFunctions_ = {}; | 29 this.apiFunctions_ = { __proto__: null }; |
30 this.unavailableApiFunctions_ = {}; | 30 this.unavailableApiFunctions_ = { __proto: null }; |
robwu
2016/04/21 10:29:33
Typo: __proto -> __proto__.
Devlin
2016/04/21 18:28:30
D'oh, done.
| |
31 this.namespace = namespace; | 31 this.namespace = namespace; |
32 } | 32 } |
33 | 33 |
34 APIFunctions.prototype = { | |
35 __proto__: null, | |
36 }; | |
37 | |
34 APIFunctions.prototype.register = function(apiName, apiFunction) { | 38 APIFunctions.prototype.register = function(apiName, apiFunction) { |
35 this.apiFunctions_[apiName] = apiFunction; | 39 this.apiFunctions_[apiName] = apiFunction; |
36 }; | 40 }; |
37 | 41 |
38 // Registers a function as existing but not available, meaning that calls to | 42 // Registers a function as existing but not available, meaning that calls to |
39 // the set* methods that reference this function should be ignored rather | 43 // the set* methods that reference this function should be ignored rather |
40 // than throwing Errors. | 44 // than throwing Errors. |
41 APIFunctions.prototype.registerUnavailable = function(apiName) { | 45 APIFunctions.prototype.registerUnavailable = function(apiName) { |
42 this.unavailableApiFunctions_[apiName] = apiName; | 46 this.unavailableApiFunctions_[apiName] = apiName; |
43 }; | 47 }; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 } | 181 } |
178 | 182 |
179 var platform = getPlatform(); | 183 var platform = getPlatform(); |
180 | 184 |
181 function Binding(apiName) { | 185 function Binding(apiName) { |
182 this.apiName_ = apiName; | 186 this.apiName_ = apiName; |
183 this.apiFunctions_ = new APIFunctions(apiName); | 187 this.apiFunctions_ = new APIFunctions(apiName); |
184 this.customHooks_ = []; | 188 this.customHooks_ = []; |
185 }; | 189 }; |
186 | 190 |
187 Binding.create = function(apiName) { | 191 $Object.defineProperty(Binding, 'create', { |
robwu
2016/04/21 10:29:33
Also use __proto__: null in the property descripto
Devlin
2016/04/21 18:28:30
I'm not as worried about avoiding throwing at the
| |
188 return new Binding(apiName); | 192 configurable: false, |
189 }; | 193 enumerable: false, |
194 value: function(apiName) { return new Binding(apiName); }, | |
195 writable: false, | |
196 }); | |
190 | 197 |
191 Binding.prototype = { | 198 Binding.prototype = { |
192 // Sneaky workaround for Object.prototype getters/setters - our prototype | 199 // Sneaky workaround for Object.prototype getters/setters - our prototype |
193 // isn't Object.prototype. SafeBuiltins (e.g. $Object.hasOwnProperty()) | 200 // isn't Object.prototype. SafeBuiltins (e.g. $Object.hasOwnProperty()) |
194 // should still work. | 201 // should still work. |
195 __proto__: null, | 202 __proto__: null, |
196 | 203 |
197 // Forward-declare properties. | 204 // Forward-declare properties. |
198 apiName_: undefined, | 205 apiName_: undefined, |
199 apiFunctions_: undefined, | 206 apiFunctions_: undefined, |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 if (functionDef.name in mod) { | 376 if (functionDef.name in mod) { |
370 throw new Error('Function ' + functionDef.name + | 377 throw new Error('Function ' + functionDef.name + |
371 ' already defined in ' + schema.namespace); | 378 ' already defined in ' + schema.namespace); |
372 } | 379 } |
373 | 380 |
374 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { | 381 if (!isSchemaNodeSupported(functionDef, platform, manifestVersion)) { |
375 this.apiFunctions_.registerUnavailable(functionDef.name); | 382 this.apiFunctions_.registerUnavailable(functionDef.name); |
376 return; | 383 return; |
377 } | 384 } |
378 | 385 |
379 var apiFunction = {}; | 386 var apiFunction = { __proto__: null }; |
robwu
2016/04/21 10:29:33
With this change, the separate apiFunctionName var
Devlin
2016/04/21 18:28:30
Done.
| |
380 apiFunction.definition = functionDef; | 387 apiFunction.definition = functionDef; |
381 var apiFunctionName = schema.namespace + '.' + functionDef.name; | 388 var apiFunctionName = schema.namespace + '.' + functionDef.name; |
382 apiFunction.name = apiFunctionName; | 389 apiFunction.name = apiFunctionName; |
383 | 390 |
384 if (!GetAvailability(apiFunctionName).is_available || | 391 if (!GetAvailability(apiFunctionName).is_available || |
385 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { | 392 (checkUnprivileged && !isSchemaAccessAllowed(functionDef))) { |
386 this.apiFunctions_.registerUnavailable(functionDef.name); | 393 this.apiFunctions_.registerUnavailable(functionDef.name); |
387 return; | 394 return; |
388 } | 395 } |
389 | 396 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
552 availability.message); | 559 availability.message); |
553 return; | 560 return; |
554 } | 561 } |
555 | 562 |
556 this.runHooks_(mod, schema); | 563 this.runHooks_(mod, schema); |
557 return mod; | 564 return mod; |
558 } | 565 } |
559 }; | 566 }; |
560 | 567 |
561 exports.$set('Binding', Binding); | 568 exports.$set('Binding', Binding); |
OLD | NEW |