eberon_rtl.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. var oberon_rtl = require("rtl.js");
  3. function extendMap(base, ext){
  4. var result = {};
  5. oberon_rtl.applyMap(base, result);
  6. oberon_rtl.applyMap(ext, result);
  7. return result;
  8. }
  9. var methods = extendMap(oberon_rtl.rtl.methods, {
  10. getMappedValue: function(map, key){
  11. if (!map.hasOwnProperty(key))
  12. throw new Error("invalid key: " + key);
  13. return map[key];
  14. },
  15. clearMap: function(map){
  16. for(var p in map)
  17. delete map[p];
  18. },
  19. clone: function(from, type, recordCons){
  20. var m = type.map;
  21. if (m !== undefined){
  22. var result = {};
  23. this.__copyMap(from, result, m);
  24. return result;
  25. }
  26. return this.__inheritedClone(from, type, recordCons);
  27. },
  28. copy: function(from, to, type){
  29. var m = type.map;
  30. if (m !== undefined){
  31. this.clearMap(to);
  32. this.__copyMap(from, to, m);
  33. }
  34. else
  35. this.__inheritedCopy(from, to, type);
  36. },
  37. __copyMap: function(from, to, type){
  38. var k;
  39. if (type === null)
  40. // shallow copy
  41. for(k in from)
  42. to[k] = from[k];
  43. else
  44. // deep copy
  45. for(k in from)
  46. to[k] = this.clone(from[k], type);
  47. },
  48. __inheritedClone: oberon_rtl.rtl.methods.clone,
  49. __inheritedCopy: oberon_rtl.rtl.methods.copy
  50. });
  51. oberon_rtl.applyMap(methods, exports);
  52. var dependencies = extendMap(oberon_rtl.rtl.dependencies, {
  53. "clone": oberon_rtl.rtl.dependencies.clone.concat(["__copyMap", "__inheritedClone"]),
  54. "copy": oberon_rtl.rtl.dependencies.copy.concat(["clearMap", "__copyMap", "__inheritedCopy"])
  55. });
  56. exports.rtl = {
  57. dependencies: dependencies,
  58. methods: methods,
  59. nodejsModule: "eberon/eberon_rtl.js"
  60. };