Bug 156022

Summary: Web Inspector: sourceMappingURL not loaded in generated script
Product: WebKit Reporter: eelco
Component: Web InspectorAssignee: Nobody <webkit-unassigned>
Severity: Normal CC: bburg, commit-queue, ggaren, graouts, joepeck, keith_miller, mark.lam, mattbaker, msaboff, nvasilyev, saam, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Mac   
OS: OS X 10.11   
Bug Depends on: 156863    
Bug Blocks:    
Description Flags
Example to reproduce the bug
[PATCH] Proposed Fix
[IMAGE] After - Test Case
[IMAGE] After - Eval Code console messages with/without sourceURL name none

Description eelco 2016-03-30 05:22:16 PDT
Created attachment 275194 [details]
Example to reproduce the bug

The source map from a generated script is not loaded.

To reproduce:
- Unzip the attachment.
- Host it by executing 'python -m SimpleHTTPServer 1234'
- Go to
- Open the Web Inspector Console (option-cmd-C)
- Look at the first error

- The error is reported as originating from the function `anonymous`, not linked to any source.

- The error is reported as originating from app.coffee:1 or at the very least from the 'Extra Script' coffeescript:3

This might be a duplicate of https://bugs.webkit.org/show_bug.cgi?id=156021
Comment 1 Radar WebKit Bug Importer 2016-03-30 05:22:38 PDT
Comment 2 Joseph Pecoraro 2016-04-14 19:40:16 PDT
This is another great reduction!

Even after fixing bug 156021, this exposes another issue. We aren't reliably detecting the sourceURL within functions created via `Function`.

console.log(Function("\n//# sourceURL=test.js\nreturn 1+1")());

I'd expect this to always create a Extra Script named "test.js" however it only does it rarely (once or twice) and then never again.
Comment 3 Joseph Pecoraro 2016-04-20 16:29:09 PDT
Hmm, the so issue here is the sourceURL/sourceMappingURL do not get added when we skip re-parsing via the CodeCache:

When constructing the executable for `Function(str)` we go through:

    frame #0: JSC::CodeCache::getFunctionExecutableFromGlobalCode
    frame #1: JSC::UnlinkedFunctionExecutable::fromGlobalCode
    frame #2: JSC::FunctionExecutable::fromGlobalCode
    frame #3: JSC::constructFunctionSkippingEvalEnabledCheck
    frame #4: JSC::constructFunction
    frame #5: JSC::constructFunction
    frame #6: JSC::callFunctionConstructor

At which point if we do not have it in the CodeCache we parse it. If we do have this in the code cache, we return the cached unlinked function executable skipping parsing.

By skipping parsing we don't update the SourceProvider with the sourceURL/sourceMappingURL, because we normally do that under JSC::Parser<>::parse.
Comment 4 Joseph Pecoraro 2016-04-21 13:23:07 PDT
Fixing the CodeCache issue then revealed a few more issues.

  1. Using CodeCache and skipping loses source directives (Function constructor)
  2. Frontend didn't properly handle a top level sourceMappingURL being a dataURL
  3. Exceptions thrown in non-resource scripts would not have resource links in
     the console, because we couldn't map them back to a resource. (no url)

Fixing all of these gets this working. I'm going to first fix the CodeCache issue separately, because I think the JavaScriptCore folks may have some input on that.
Comment 5 Joseph Pecoraro 2016-04-21 15:43:03 PDT
Created attachment 276973 [details]
[PATCH] Proposed Fix
Comment 6 Joseph Pecoraro 2016-04-21 15:43:27 PDT
Created attachment 276974 [details]
[IMAGE] After - Test Case
Comment 7 Joseph Pecoraro 2016-04-21 15:43:55 PDT
Created attachment 276975 [details]
[IMAGE] After - Eval Code console messages with/without sourceURL name
Comment 8 WebKit Commit Bot 2016-04-21 15:44:42 PDT
Attachment 276973 [details] did not pass style-queue:

ERROR: Source/JavaScriptCore/inspector/ScriptCallFrame.h:44:  The parameter name "sourceID" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 1 in 22 files

If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Geoffrey Garen 2016-04-21 16:58:57 PDT
Comment on attachment 276973 [details]
[PATCH] Proposed Fix

Comment 10 WebKit Commit Bot 2016-04-21 17:49:49 PDT
Comment on attachment 276973 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 276973

Committed r199852: <http://trac.webkit.org/changeset/199852>
Comment 11 WebKit Commit Bot 2016-04-21 17:49:54 PDT
All reviewed patches have been landed.  Closing bug.