web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  1. var NATIVE_WEAK_MAP = require('../internals/native-weak-map');
  2. var global = require('../internals/global');
  3. var isObject = require('../internals/is-object');
  4. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  5. var objectHas = require('../internals/has');
  6. var shared = require('../internals/shared-store');
  7. var sharedKey = require('../internals/shared-key');
  8. var hiddenKeys = require('../internals/hidden-keys');
  9. var WeakMap = global.WeakMap;
  10. var set, get, has;
  11. var enforce = function (it) {
  12. return has(it) ? get(it) : set(it, {});
  13. };
  14. var getterFor = function (TYPE) {
  15. return function (it) {
  16. var state;
  17. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  18. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  19. } return state;
  20. };
  21. };
  22. if (NATIVE_WEAK_MAP) {
  23. var store = shared.state || (shared.state = new WeakMap());
  24. var wmget = store.get;
  25. var wmhas = store.has;
  26. var wmset = store.set;
  27. set = function (it, metadata) {
  28. metadata.facade = it;
  29. wmset.call(store, it, metadata);
  30. return metadata;
  31. };
  32. get = function (it) {
  33. return wmget.call(store, it) || {};
  34. };
  35. has = function (it) {
  36. return wmhas.call(store, it);
  37. };
  38. } else {
  39. var STATE = sharedKey('state');
  40. hiddenKeys[STATE] = true;
  41. set = function (it, metadata) {
  42. metadata.facade = it;
  43. createNonEnumerableProperty(it, STATE, metadata);
  44. return metadata;
  45. };
  46. get = function (it) {
  47. return objectHas(it, STATE) ? it[STATE] : {};
  48. };
  49. has = function (it) {
  50. return objectHas(it, STATE);
  51. };
  52. }
  53. module.exports = {
  54. set: set,
  55. get: get,
  56. has: has,
  57. enforce: enforce,
  58. getterFor: getterFor
  59. };