<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>180006</bug_id>
          
          <creation_ts>2017-11-24 07:57:21 -0800</creation_ts>
          <short_desc>not a function, is 4.538223e-316 instead: function is optimized to a... number?</short_desc>
          <delta_ts>2017-11-27 14:58:10 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Safari 10</version>
          <rep_platform>iPhone / iPad</rep_platform>
          <op_sys>iOS 10.3</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>awerlang17</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ap</cc>
    
    <cc>fpizlo</cc>
    
    <cc>saam</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1374603</commentid>
    <comment_count>0</comment_count>
    <who name="">awerlang17</who>
    <bug_when>2017-11-24 07:57:21 -0800</bug_when>
    <thetext># Overview:

We&apos;re getting an exception where a function is expected but it&apos;s a number instead.

The function is a class method part of Angular@4.3.6. Written in TypeScript and compiled to ES5 as (shortened to relevant bits):

    &quot;use strict&quot;;
    var Router = /** @class */ (function () {
        function Router() {
        }
        Router.prototype.serializeUrl = function (url) { return this.urlSerializer.serialize(url); };
        return Router;
    }());

Couldn&apos;t it be a user-level code changing the function to become a number? I think not. I added the following code to initialization:

    // FIXME: attempt to troubleshoot this.router.serializeUrl is not a function on Safari
    const serializeUrl = router.serializeUrl;
    Object.defineProperty(router, &apos;serializeUrl&apos;, {
        configurable: false,
        get: () =&gt; serializeUrl,
        set: (value) =&gt; { throw new Error(&apos;this.router.serializeUrl = &apos; + value) },
    });
    Object.defineProperty(Router.prototype, &apos;serializeUrl&apos;, {
        configurable: false,
        get: () =&gt; serializeUrl,
        set: (value) =&gt; { throw new Error(&apos;Router.prototype.serializeUrl = &apos; + value) },
    });

It failed again and this trap didn&apos;t run. How the function could be replaced without going through these paths?

Because it happens after a few successful invocations of ditto function, I believe the culprit lies in the optimizer (of course, it&apos;s not a valid replacement for a function, so that makes me wonder why it happens)

# Steps to Reproduce:

Unfortunately, it&apos;s unpredictable when it&apos;s going to happen. The function in question runs a few times until the error occurs. It may not happen at all for a given user, but keeps happening. When it fails, it fails for the same function / call site every time.

# Actual Results: 

An exception is thrown:
    TypeError: this.router.serializeUrl is not a function. (In &apos;this.router.serializeUrl(this.urlTree)&apos;, &apos;this.router.serializeUrl&apos; is 4.538223e-316)

The floating point number reported is different every time.

# Expected Results: 

Function should be invoked w/o problems.

# Build Date &amp; Hardware: 

Sample user agent: Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 Mobile/14G60 Safari/602.1

# Additional Builds and Platforms: 

Wasn&apos;t reported on iOS Safari !== 10.x so far. Nor other browsers &amp; platforms (okay on Mac OS X, Windows, Chrome, Firefox, Edge)

# Additional Information:

Reported as well at https://github.com/angular/angular/issues/16717. The Angular team dismissed the issue because policies.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1374621</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2017-11-24 11:22:17 -0800</bug_when>
    <thetext>Could you please provide a reproducible case? I don’t think that this kind of an issue can be fixed based on a description alone.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1374740</commentid>
    <comment_count>2</comment_count>
    <who name="">awerlang17</who>
    <bug_when>2017-11-26 09:52:13 -0800</bug_when>
    <thetext>I published at https://awerlang.github.io/webkit180006/

I&apos;m afraid is not easy to reproduce it though, as it just happens.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1375144</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2017-11-27 14:58:10 -0800</bug_when>
    <thetext>Thank you! What specifically should I try on this webpage to see the problem? It&apos;s OK if it takes a reasonable number of tries to reproduce, but hopefully we won&apos;t need to be manually interacting with the page for hours until this happens.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>