<commit_before>/**
@module @ember/object
*/

import { assert } from 'ember-debug';
import { HAS_NATIVE_PROXY } from 'ember-utils';
import { descriptorFor, meta as metaFor, peekMeta, DESCRIPTOR, UNDEFINED } from './meta';
import { overrideChains } from './property_events';
import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, MANDATORY_SETTER } from 'ember/features';
// ..........................................................
// DESCRIPTOR
//

/**
  Objects of this type can implement an interface to respond to requests to
  get and set. The default implementation handles simple properties.

  @class Descriptor
  @private
*/
export function Descriptor() {
  this.isDescriptor = true;
}

// ..........................................................
// DEFINING PROPERTIES API
//

export function MANDATORY_SETTER_FUNCTION(name) {
  function SETTER_FUNCTION(value) {
    let m = peekMeta(this);
    if (!m.isInitialized(this)) {
      m.writeValues(name, value);
    } else {
      assert(`You must use set() to set the \`${name}\` property (of ${this}) to \`${value}\`.`, false);
    }
  }

  SETTER_FUNCTION.isMandatorySetter = true;
  return SETTER_FUNCTION;
}

export function DEFAULT_GETTER_FUNCTION(name) {
  return function GETTER_FUNCTION() {
    let meta = peekMeta(this);
    if (meta !== undefined) {
      return meta.peekValues(name);
    }
  };
}

export function INHERITING_GETTER_FUNCTION(name) {
  function IGETTER_FUNCTION() {
    let meta = peekMeta(this);
    let val;
    if (meta !== undefined) {
      val = meta.readInheritedValue('values', name);
    }

    if (val === UNDEFINED) {
      let proto = Object.getPrototypeOf(this);
      return proto && proto[name];
    } else {
      return val;
    }
  }

  IGETTER_FUNCTION.isInheritingGetter = true;
  return IGETTER_FUNCTION;
}

let DESCRIPTOR_GETTER_FUNCTION;

if (EMBER_METAL_ES5_GETTERS) {
  DESCRIPTOR_GETTER_FUNCTION = function(name, descriptor) {
    return function CPGETTER_FUNCTION() {
      return descriptor.get(this, name);
    };
  };
} else if (DESCRIPTOR_TRAP) {
  // Future traveler, although this code looks scary. It merely exists in
  // development to aid in development asertions. Production builds of
  // ember strip this entire branch out.
  let messageFor = function(obj, keyName, property, value) {
    return `You attempted to access the \`${keyName}.${property}\` property ` +
      `(of ${obj}). Due to certain internal implementation details of Ember, ` +
      `the \`${keyName}\` property previously contained an internal "descriptor" ` +
      `object (a private API), therefore \`${keyName}.${property}\` would have ` +
      `been \`${String(value).replace(/\n/g, ' ')}\`. This internal implementation ` +
      `detail was never intended to be a public (or even intimate) API.\n\n` +
      `This internal implementation detail has now changed and the (still private) ` +
      `"descriptor" object has been relocated to the object's "meta" (also a ` +
      `private API). Soon, accessing \`${keyName}\` on this object will ` +
      `return the computed value (see RFC #281 for more details).\n\n` +
      `If you are seeing this error, you are likely using an addon that ` +
      `relies on this now-defunct private implementation detail. If you can, ` +
      `find out which addon is doing this from the stack trace below and ` +
      `report this bug to the addon authors. If you feel stuck, the Ember ` +
      `Community Slack (https://ember-community-slackin.herokuapp.com/) ` +
      `may be able to offer some help.\n\n` +
      `If you are an addon author and need help transitioning your code, ` +
      `please get in touch in the #dev-ember channel in the Ember Community ` +
      `Slack.`;
  };

  let trapFor;

  if (HAS_NATIVE_PROXY) {
    /* globals Proxy */
    trapFor = function(obj, keyName, descriptor) {
      return new Proxy(descriptor, {
        get(descriptor, property) {
          if (property === DESCRIPTOR) {
            return descriptor;
          } else if (property === 'toString' || property == 'valueOf' ||
            property == 'inspect' || property == 'constructor' ||
            (Symbol && property === Symbol.toPrimitive)) {
            return () => '[COMPUTED PROPERTY]';
          }

          assert(messageFor(obj, keyName, property, descriptor[property]));
        }
      });
    };
  } else {
    trapFor = function(obj, keyName, descriptor) {
      let trap = Object.create(null);

      Object.defineProperty(trap, DESCRIPTOR, {
        configurable: false,
        enumerable: false,
        writable: false,
        value: descriptor
      });

      trap.toString = trap.valueOf = () => '[COMPUTED PROPERTY]';

      // Without a proxy, we can only trap the "likely" properties
      ['isDescriptor', 'setup', 'teardown', 'get', '_getter', 'set', '_setter', 'meta'].forEach(property => {
        Object.defineProperty(trap, property, {
          configurable: false,
          enumerable: false,
          get() {
            assert(messageFor(obj, keyName, property, descriptor[property]));
          }
        });
      });<commit_msg>[BUGFIX beta] Add additional escape hatches for descriptorTrap.<commit_after>/**
@module @ember/object
*/

import { assert } from 'ember-debug';
import { HAS_NATIVE_PROXY } from 'ember-utils';
import { descriptorFor, meta as metaFor, peekMeta, DESCRIPTOR, UNDEFINED } from './meta';
import { overrideChains } from './property_events';
import { DESCRIPTOR_TRAP, EMBER_METAL_ES5_GETTERS, MANDATORY_SETTER } from 'ember/features';
// ..........................................................
// DESCRIPTOR
//

/**
  Objects of this type can implement an interface to respond to requests to
  get and set. The default implementation handles simple properties.

  @class Descriptor
  @private
*/
export function Descriptor() {
  this.isDescriptor = true;
}

// ..........................................................
// DEFINING PROPERTIES API
//

export function MANDATORY_SETTER_FUNCTION(name) {
  function SETTER_FUNCTION(value) {
    let m = peekMeta(this);
    if (!m.isInitialized(this)) {
      m.writeValues(name, value);
    } else {
      assert(`You must use set() to set the \`${name}\` property (of ${this}) to \`${value}\`.`, false);
    }
  }

  SETTER_FUNCTION.isMandatorySetter = true;
  return SETTER_FUNCTION;
}

export function DEFAULT_GETTER_FUNCTION(name) {
  return function GETTER_FUNCTION() {
    let meta = peekMeta(this);
    if (meta !== undefined) {
      return meta.peekValues(name);
    }
  };
}

export function INHERITING_GETTER_FUNCTION(name) {
  function IGETTER_FUNCTION() {
    let meta = peekMeta(this);
    let val;
    if (meta !== undefined) {
      val = meta.readInheritedValue('values', name);
    }

    if (val === UNDEFINED) {
      let proto = Object.getPrototypeOf(this);
      return proto && proto[name];
    } else {
      return val;
    }
  }

  IGETTER_FUNCTION.isInheritingGetter = true;
  return IGETTER_FUNCTION;
}

let DESCRIPTOR_GETTER_FUNCTION;

if (EMBER_METAL_ES5_GETTERS) {
  DESCRIPTOR_GETTER_FUNCTION = function(name, descriptor) {
    return function CPGETTER_FUNCTION() {
      return descriptor.get(this, name);
    };
  };
} else if (DESCRIPTOR_TRAP) {
  // Future traveler, although this code looks scary. It merely exists in
  // development to aid in development asertions. Production builds of
  // ember strip this entire branch out.
  let messageFor = function(obj, keyName, property, value) {
    return `You attempted to access the \`${keyName}.${property}\` property ` +
      `(of ${obj}). Due to certain internal implementation details of Ember, ` +
      `the \`${keyName}\` property previously contained an internal "descriptor" ` +
      `object (a private API), therefore \`${keyName}.${property}\` would have ` +
      `been \`${String(value).replace(/\n/g, ' ')}\`. This internal implementation ` +
      `detail was never intended to be a public (or even intimate) API.\n\n` +
      `This internal implementation detail has now changed and the (still private) ` +
      `"descriptor" object has been relocated to the object's "meta" (also a ` +
      `private API). Soon, accessing \`${keyName}\` on this object will ` +
      `return the computed value (see RFC #281 for more details).\n\n` +
      `If you are seeing this error, you are likely using an addon that ` +
      `relies on this now-defunct private implementation detail. If you can, ` +
      `find out which addon is doing this from the stack trace below and ` +
      `report this bug to the addon authors. If you feel stuck, the Ember ` +
      `Community Slack (https://ember-community-slackin.herokuapp.com/) ` +
      `may be able to offer some help.\n\n` +
      `If you are an addon author and need help transitioning your code, ` +
      `please get in touch in the #dev-ember channel in the Ember Community ` +
      `Slack.`;
  };

  let trapFor;

  if (HAS_NATIVE_PROXY) {
    /* globals Proxy */
    trapFor = function(obj, keyName, descriptor) {
      return new Proxy(descriptor, {
        get(descriptor, property) {
          if (property === DESCRIPTOR) {
            return descriptor;
          } else if (
            property === 'prototype' ||
            property === 'constructor' ||
            property === 'nodeType'
          ) {
            return undefined;
          } else if (
            property === 'toString' ||
            property === 'valueOf' ||
            property === 'inspect' ||
            Symbol && property === Symbol.toPrimitive ||
            Symbol && property === Symbol.toStringTag
          ) {
            return () => '[COMPUTED PROPERTY]';
          }

          assert(messageFor(obj, keyName, property, descriptor[property]));
        }
      });
    };
  } else {
    trapFor = function(obj, keyName, descriptor) {
      let trap = Object.create(null);

      Object.defineProperty(trap, DESCRIPTOR, {
        configurable: false,
        enumerable: false,
        writable: false,
        value: descriptor
      });

      trap.toString = trap.valueOf = () => '[COMPUTED PROPERTY]';

      // Without a proxy, we can only trap the "likely" properties
      ['isDescriptor', 'setup', 'teardown', 'get', '_getter', 'set', '_setter', 'meta'].forEach(property => {
        Object.defineProperty(trap, property, {
          configurable: false,
          enumerable: false,
          get() {
            assert(messageFor(obj, keyName, property, descriptor[property]));
          }
        });
      });
{'fraction_non_alphanumeric': 0.14270793771363463, 'fraction_numerical': 0.0009494872768704899, 'mean_word_length': 2.593654042988741, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5380745', 'n_tokens_mistral': 3093, 'n_tokens_neox': 3012, 'n_words': 932}