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.

14 lines
772 B

  1. var isObject = require('../internals/is-object');
  2. // `ToPrimitive` abstract operation
  3. // https://tc39.es/ecma262/#sec-toprimitive
  4. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  5. // and the second argument - flag - preferred type is a string
  6. module.exports = function (input, PREFERRED_STRING) {
  7. if (!isObject(input)) return input;
  8. var fn, val;
  9. if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  10. if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
  11. if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  12. throw TypeError("Can't convert object to primitive value");
  13. };