Loading ...
Sorry, an error occurred while loading the content.

61Re: [caplet] ADsafe, Take 3

Expand Messages
  • Mike Samuel
    Oct 3, 2007
    • 0 Attachment
      I dislike blacklists.  See comments on hasOwnProperty below.

      > var reject = function check(object, name) {
      > return !object || !name || typeof object === 'function' ||
      > typeof name !== 'string' || exclude[name] ||

      Perhaps exclude.hasOwnProperty(name)?
      Right now you'll exclude valueOf, though whether that's intentional I don't know.

      Also, if you do hasOwnProperty or (name in exclude) you're guaranteed not to cause any function calls as a result of coercing a non boolean value to a boolean.

      Since your language is advertised as non-prototypical, hasOwnProperty would seem more appropriate.
       
      > name.charAt[0] === '_' || name.indexOf('$') >= 0;

      Ok.  Since you've checked name is a string, it's safe to access charAt and indexOf directly.  Unless someone can poison the String, but that means they've already gained access

      And the prefix _ check should eliminate Firefox reserved names such as __parent__, __proto__, and __caller__.


      > };

      > return {
      > get: function (object, name) {
      > var value;
      > if (reject(object, name)) {
      > return;
      > }
      > value = object[name];
      > if (typeof value === 'function') {
      > return;
      > }

      Why disallow returning functions?
      If your concern is that using a getter breaks the association between the method and its `this` value, you can always return a bound method a la function (binding, method) { return function () { return Function.apply.apply(method, [method, binding].concat(arguments)); }; }


      > return value;
      > },
      > set: function (object, name, value) {
      > if (reject(object, name) || typeof value === 'function') {
      > return;
      > }
      > object[name] = value;
      > return object;
      > }
      > };
      > }();

    • Show all 17 messages in this topic