JavaScript core-js/babel-polyfill polyfilled functions appear as [native code] core-js babel,core-js babel-polyfill,core-js babel

Functions that were polyfilled with core-js (for example, babel-polyfill) appear as native.

Promise.race.toString() produces:

function race() {
    [native code]
}

So does Object.values.toString().

While they are certainly not browser's native implementations. The example is Babel REPL page.

How can a developer programmatically check that a function is not native implementation but a polyfill that mimics native function (for instance, when it is known that a particular polyfill may cause problems in the application)?

Usually native code regexp helps, but it is certainly not the case.

How can source code be retrieved from such functions? I'm primarily interested in Node.js but cross-platform solution is welcome.

How exactly was this trick done? I cannot find nothing for native code search in core-js and babel-polyfill source code.

Answer:1

core-js attempts to make its polyfilled functionality appear as natively implemented by replacing Function.prototype.toString here with a version that falls back on the default, but allows core-js to override the string value if it wants by setting a value at fn[SRC].

You can see farther up in that file here it assigns fn[SRC], specifically

if(isFunction)has(val, SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));

If you inspect TPL in this case it is ["function ", "() { [native code] }"], so when called with .join(String(key)) you end up with the

function race() { [native code] }

that you see in your output.

Answer:2

Example HTML page: <div> <ul> <li> 1 </li> <li> 2 </li> </ul> </div> Then in a ajax request I get <div> <ul> <li> ...

Example HTML page: <div> <ul> <li> 1 </li> <li> 2 </li> </ul> </div> Then in a ajax request I get <div> <ul> <li> ...

I am trying to format a number upon input, where you can only insert valid numbers. I have everything working except for the decimal. The input box allows me it insert as many decimals as I would like,...

I am trying to format a number upon input, where you can only insert valid numbers. I have everything working except for the decimal. The input box allows me it insert as many decimals as I would like,...

  1. input allow only numbers
  2. input allow only alphanumeric
  3. input allow only numbers and dot
  4. input allow only numbers angular
  5. input allow only letters
  6. input allow only 2 decimal places
  7. input allow only numbers jquery
  8. input allow only numbers and decimal
  9. input allow only numbers react
  10. input allow only images
  11. input allow only integers
  12. input allow only numbers angular 2
  13. input allow only letters and numbers
  14. input allow only digits
  15. input allow only whole numbers
  16. input allow only numbers and one dot
  17. input allow only positive numbers
  18. input allow only one number
  19. input allow only numbers regex
  20. input allow only two numbers

updated. I have stored my data in an array of tuples: called $scope.unique. basically it looks like this: [["Chris Ivory", "Alfred Morris"], ["CJ", "DJAX"], ["DJ", "CX"]["Willie", "Fred]]. The ...

updated. I have stored my data in an array of tuples: called $scope.unique. basically it looks like this: [["Chris Ivory", "Alfred Morris"], ["CJ", "DJAX"], ["DJ", "CX"]["Willie", "Fred]]. The ...

  1. ng repeat with arrays
  2. repeat arrays matlab
  3. repeat arrays python
  4. repeat arrays
  5. ng-repeat with two arrays
  6. ng-repeat with multiple arrays
  7. ng-repeat with 2 arrays
  8. ng-repeat with nested arrays

Let's consider a definition as function Stone() { this.x = 0; this.y = 400; }; I instantiate an object var st = new Stone; var ll = [st]; var remov = ll.splice(0, 1); ...

Let's consider a definition as function Stone() { this.x = 0; this.y = 400; }; I instantiate an object var st = new Stone; var ll = [st]; var remov = ll.splice(0, 1); ...

  1. javascript splice return object