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 // |value| is eventually added to |m|, the exposed API. Make copies | 487 var value = propertyDef.value; |
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 | |
498 if (value) { | 488 if (value) { |
499 // Values may just have raw types as defined in the JSON, such | 489 // Values may just have raw types as defined in the JSON, such |
500 // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here. | 490 // as "WINDOW_ID_NONE": { "value": -1 }. We handle this here. |
501 // TODO(kalman): enforce that things with a "value" property can't | 491 // TODO(kalman): enforce that things with a "value" property can't |
502 // define their own types. | 492 // define their own types. |
503 var type = propertyDef.type || typeof(value); | 493 var type = propertyDef.type || typeof(value); |
504 if (type === 'integer' || type === 'number') { | 494 if (type === 'integer' || type === 'number') { |
505 value = parseInt(value); | 495 value = parseInt(value); |
506 } else if (type === 'boolean') { | 496 } else if (type === 'boolean') { |
507 value = value === 'true'; | 497 value = value === 'true'; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 availability.message); | 555 availability.message); |
566 return; | 556 return; |
567 } | 557 } |
568 | 558 |
569 this.runHooks_(mod, schema); | 559 this.runHooks_(mod, schema); |
570 return mod; | 560 return mod; |
571 } | 561 } |
572 }; | 562 }; |
573 | 563 |
574 exports.$set('Binding', Binding); | 564 exports.$set('Binding', Binding); |
OLD | NEW |