Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map on Safari throws error when constructor is passed arguments #1650

Closed
benhughes opened this issue Jan 22, 2015 · 12 comments · Fixed by #1940
Closed

Map on Safari throws error when constructor is passed arguments #1650

benhughes opened this issue Jan 22, 2015 · 12 comments · Fixed by #1940
Assignees
Labels

Comments

@benhughes
Copy link

After compiling the following with Traceur (using es6ify):

var some var = new Map([
      ['key', 'data']
])

Safari throws

[Error] TypeError: Map constructor does not accept arguments

I see from http://kangax.github.io/compat-table/es6/ that Safari does not support this feature of ES6. Are there any plans to polyfill it in Safari?

Traceur version: 0.0.79
Safari version: 8.0.2

@arv
Copy link
Collaborator

arv commented Jan 22, 2015

We have a polyfill, so it is just a matter of changing the detection.

@paulftw
Copy link

paulftw commented May 4, 2015

+1
This breaks Angular 2.0 in Safari

@paulftw
Copy link

paulftw commented May 5, 2015

As a workaround I modified polyfillMap(...) in src/runtime/polyfills/Map.js - added the following snippet:

  if (!global.Map) {
    global.Map = Map;
  } else {
    try {
      new global.Map([['k', 'v']]);
    } catch (e) {
      // Native Map doesn't support constructor arguments (Safari 8 and below).
      global.Map = Map;
    }
  }

@hydrotik
Copy link

hydrotik commented May 7, 2015

+1 Angular 2.0 broken on Safari

@caitp
Copy link
Contributor

caitp commented May 7, 2015

it works in WebKit Nightly though, or did last I checked =) Just be sure to use WK Nightly during your demos ;)

@arv arv added the bug label May 7, 2015
@arv arv self-assigned this May 7, 2015
@arv
Copy link
Collaborator

arv commented May 7, 2015

I want to fix this... I just haven't had enough time to get it fixed.

  1. If the browser has no Symbol support use polyfill.
  2. If the browser has no Symbol.iterator support use polyfill.
  3. If new Set([1]).size !== 1 use polyfill.

Patches welcome.

@zloirock
Copy link

zloirock commented May 7, 2015

@arv
Copy link
Collaborator

arv commented May 7, 2015

@zloirock I don't agree with that list. iterator closing is an abomination. I wish I had been stronger in opposing it at TC39. It requires all your code to be wrapped in a try/catch which is insane.

@zloirock
Copy link

zloirock commented May 7, 2015

@arv abomination, but required for compliance with the specification. Wrapper for constructor much better complete replacement of collection.

@arv
Copy link
Collaborator

arv commented May 7, 2015

@zloirock No doubt. We just have to prioritize things based on importance and this one is very low.

@paulftw
Copy link

paulftw commented May 8, 2015

@arv I've posted a workaround earlier, if you are too busy - I don't mind spending some time on a mature pull request.

Only problem is I have no idea what is considered an acceptable PR for traceur.

Could you point out a similar patch to use as scaffolding? Something small that's been accepted recently, addresses a similar feature, has tests, etc.
I'm aware of CONTRIBUTING.md.

BTW I'm not sure your test #3 will work though - Map constructor seems to throw an exception if any params are present.

@arv
Copy link
Collaborator

arv commented May 8, 2015

Yeah 3 needs a try/catch.

This commit might be serve as inspiration: 1951203

Here is where the setup is done: https://github.com/google/traceur-compiler/blob/master/src/runtime/polyfills/Map.js#L195-L209 and similarly for Set.

We might also need to have a way to detect if native Symbols are supported: https://github.com/google/traceur-compiler/blob/master/src/runtime/runtime.js#L462-L473

arv added a commit to arv/traceur-compiler that referenced this issue May 17, 2015
Safari does not support ES6 Map/Set correctly which leads to trouble.
Be more strict in detecting whether the native Map/Set is good enough.

Fixes google#1650, google#1810
arv added a commit to arv/traceur-compiler that referenced this issue May 18, 2015
Safari does not support ES6 Map/Set correctly which leads to trouble.
Be more strict in detecting whether the native Map/Set is good enough.

Fixes google#1650, google#1810
@arv arv closed this as completed in #1940 May 18, 2015
@arv arv removed the in progress label May 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants