| 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'); |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 if (propertyName in m) | 477 if (propertyName in m) |
| 478 return; // TODO(kalman): be strict like functions/events somehow. | 478 return; // TODO(kalman): be strict like functions/events somehow. |
| 479 if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion)) | 479 if (!isSchemaNodeSupported(propertyDef, platform, manifestVersion)) |
| 480 return; | 480 return; |
| 481 if (!GetAvailability(schema.namespace + "." + | 481 if (!GetAvailability(schema.namespace + "." + |
| 482 propertyName).is_available || | 482 propertyName).is_available || |
| 483 (checkUnprivileged && !isSchemaAccessAllowed(propertyDef))) { | 483 (checkUnprivileged && !isSchemaAccessAllowed(propertyDef))) { |
| 484 return; | 484 return; |
| 485 } | 485 } |
| 486 | 486 |
| 487 var value = propertyDef.value; | 487 // |value| is eventually added to |m|, the exposed API. Make copies |
| 488 // of everything from the schema. (The schema is also frozen, so as long |
| 489 // as we don't make any modifications, shallow copies are fine.) |
| 490 var value; |
| 491 if ($Array.isArray(propertyDef.value)) |
| 492 value = $Array.slice(propertyDef.value); |
| 493 else if (typeof propertyDef.value === 'object') |
| 494 value = $Object.assign({}, propertyDef.value); |
| 495 else |
| 496 value = propertyDef.value; |
| 497 |
| 488 if (value) { | 498 if (value) { |
| 489 // Values may just have raw types as defined in the JSON, such | 499 // Values may just have raw types as defined in the JSON, such |
| 490 // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here. | 500 // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here. |
| 491 // TODO(kalman): enforce that things with a "value" property can't | 501 // TODO(kalman): enforce that things with a "value" property can't |
| 492 // define their own types. | 502 // define their own types. |
| 493 var type = propertyDef.type || typeof(value); | 503 var type = propertyDef.type || typeof(value); |
| 494 if (type === 'integer' || type === 'number') { | 504 if (type === 'integer' || type === 'number') { |
| 495 value = parseInt(value); | 505 value = parseInt(value); |
| 496 } else if (type === 'boolean') { | 506 } else if (type === 'boolean') { |
| 497 value = value === 'true'; | 507 value = value === 'true'; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 availability.message); | 565 availability.message); |
| 556 return; | 566 return; |
| 557 } | 567 } |
| 558 | 568 |
| 559 this.runHooks_(mod, schema); | 569 this.runHooks_(mod, schema); |
| 560 return mod; | 570 return mod; |
| 561 } | 571 } |
| 562 }; | 572 }; |
| 563 | 573 |
| 564 exports.$set('Binding', Binding); | 574 exports.$set('Binding', Binding); |
| OLD | NEW |