Various arguments optimisations in codegen fail to account for arguments being in lexical record
https://bugs.webkit.org/show_bug.cgi?id=137617

Reviewed by Michael Saboff.

Rework the way we track |arguments| references so that we don't try
to use the |arguments| reference on the stack if it's not safe.

To do this without nuking performance it was necessary to update
the parser to track modification of the |arguments| reference
itself.

* bytecode/CodeBlock.cpp:
* bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::BytecodeGenerator):
(JSC::BytecodeGenerator::willResolveToArguments):
(JSC::BytecodeGenerator::uncheckedLocalArgumentsRegister):
(JSC::BytecodeGenerator::emitCall):
(JSC::BytecodeGenerator::emitConstruct):
(JSC::BytecodeGenerator::emitEnumeration):
(JSC::BytecodeGenerator::uncheckedRegisterForArguments): Deleted.
* bytecompiler/BytecodeGenerator.h:
(JSC::BytecodeGenerator::hasSafeLocalArgumentsRegister):
* bytecompiler/NodesCodegen.cpp:
(JSC::BracketAccessorNode::emitBytecode):
(JSC::DotAccessorNode::emitBytecode):
(JSC::getArgumentByVal):
(JSC::CallFunctionCallDotNode::emitBytecode):
(JSC::ApplyFunctionCallDotNode::emitBytecode):
(JSC::ArrayPatternNode::emitDirectBinding):
* interpreter/StackVisitor.cpp:
(JSC::StackVisitor::Frame::existingArguments):
* parser/Nodes.h:
(JSC::ScopeNode::modifiesArguments):
* parser/Parser.cpp:
(JSC::Parser<LexerType>::parseInner):
* parser/Parser.h:
(JSC::Scope::getCapturedVariables):
* parser/ParserModes.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174821 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[Win] Test gardening after r174796.

Now that Windows DRT matches Mac's output, we can get rid of some custom test expecations.

* platform/win/fast/dom/window-load-crash-expected.txt: Removed.
* platform/win/fast/images/crossfade-client-not-removed-crash-expected.txt: Removed.
* platform/win/fast/ruby/before-block-doesnt-crash-expected.txt: Removed.
* platform/win/fast/ruby/before-table-doesnt-crash-expected.txt: Removed.
* platform/win/fast/ruby/generated-before-counter-doesnt-crash-expected.txt: Removed.
* platform/win/loader/image-loader-adoptNode-assert-expected.txt: Removed.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174822 268f45cc-cd09-0410-ab3c-d52691b4dbfc
[Mac] Represent AVMediaSelectionOptions as AudioTracks
https://bugs.webkit.org/show_bug.cgi?id=137474

Reviewed by Brent Fulgham.

Source/WebCore:

Test: http/tests/media/hls/hls-audio-tracks.html

Support selecting audio "tracks" in HLS streams by exposing AVMediaSelectionOptions
as entries in the video's AudioTrackList.

AVMediaSessionGroups and AVPlayerItems don't have KVO or notifications to track when options
are selected and deselected, so wrap AVMediaSessionGroup and AVMediaSessionOption in C++
wrappers. Each AVMediaSelectionGroup can have only one AVMediaSelectionOption selected at a
time, so the wrapper will take care of answering which AVMediaSelectionOption is currently
selected, as without KVO notifications, asking the AVMediaSelectionGroup directly is
inconsistent. Because setting the selected option multiple times in the same run-loop can
cause flakiness, coalesce calls to setSelectedOption() by setting a one-shot timer to do
the actual selection in the next run-loop.

* platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.h: Added.
(WebCore::MediaSelectionOptionAVFObjC::avMediaSelectionOption):
(WebCore::MediaSelectionOptionAVFObjC::clearGroup): Clear backpointer to group from option.
(WebCore::MediaSelectionGroupAVFObjC::selectedOption): Simple accessor.
(WebCore::MediaSelectionGroupAVFObjC::options):  Simple accessor.
(WebCore::MediaSelectionGroupAVFObjC::avMediaSelectionGroup): Simple accessor.
* platform/graphics/avfoundation/MediaSelectionGroupAVFObjC.mm: Added.
(WebCore::MediaSelectionOptionAVFObjC::create): Simple factory method.
(WebCore::MediaSelectionOptionAVFObjC::MediaSelectionOptionAVFObjC): Simple constructor.
(WebCore::MediaSelectionOptionAVFObjC::setSelected): Pass through to MediaSelectionGroupAVFObjC.
(WebCore::MediaSelectionOptionAVFObjC::selected): Ditto.
(WebCore::MediaSelectionOptionAVFObjC::index): Return index of this object in the group's object.
(WebCore::MediaSelectionGroupAVFObjC::create):
(WebCore::MediaSelectionGroupAVFObjC::MediaSelectionGroupAVFObjC):
(WebCore::MediaSelectionGroupAVFObjC::~MediaSelectionGroupAVFObjC):
(WebCore::MediaSelectionGroupAVFObjC::updateOptions): Discover added or removed options.
(WebCore::MediaSelectionGroupAVFObjC::setSelectedOption): Set a one shot timer to coalesce multiple calls.
(WebCore::MediaSelectionGroupAVFObjC::selectionTimerFired): Set the selected AVSelectionOption.

Modify AVTrackPrivateAVFObjCImpl to support both AVPlayerItemTracks and these new
MediaSelectionOptionAVFObjC objects.

* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.h:
(WebCore::AVTrackPrivateAVFObjCImpl::mediaSelectionOption): Simple accessor.
* platform/graphics/avfoundation/AVTrackPrivateAVFObjCImpl.mm:
(WebCore::AVTrackPrivateAVFObjCImpl::AVTrackPrivateAVFObjCImpl):  Simple constructor.
(WebCore::AVTrackPrivateAVFObjCImpl::~AVTrackPrivateAVFObjCImpl): Simple destructor.
(WebCore::AVTrackPrivateAVFObjCImpl::enabled): Use MediaSelectionOptionAVFObjC, if present.
(WebCore::AVTrackPrivateAVFObjCImpl::setEnabled): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::audioKind): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::videoKind): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::index): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::id): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::label): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::language): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::languageForAVMediaSelectionOption): Ditto.
(WebCore::AVTrackPrivateAVFObjCImpl::trackID): Ditto.

Allow AudioTrackPrivateAVFObjC and VideoTrackPrivateAVFObjC to be created with
a MediaSelectionOptionAVFObjC.

* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.h:
(WebCore::AudioTrackPrivateAVFObjC::create): Takes a MediaSelectionOptionAVFObjC.
* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm:
(WebCore::AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC): Simple constructor.
(WebCore::AudioTrackPrivateAVFObjC::setMediaSelectionOption): Create a new AVTrackPrivateAVFObjCImpl.
(WebCore::AudioTrackPrivateAVFObjC::mediaSelectionOption): Simple accessor.
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.cpp:
(WebCore::VideoTrackPrivateAVFObjC::VideoTrackPrivateAVFObjC): Simple constructor.
(WebCore::VideoTrackPrivateAVFObjC::setMediaSelectonOption): Create a new AVTrackPrivateAVFObjCImpl.
(WebCore::VideoTrackPrivateAVFObjC::mediaSelectionOption): Simple accessor.
* platform/graphics/avfoundation/objc/VideoTrackPrivateAVFObjC.h:

Because IDs are not necessarily unique across AVPlayerItemTracks and AVMediaSelectionOptions,
use the index of the track or option instead of it's self-declared ID for ordering for the
trackIndex.

* platform/graphics/avfoundation/objc/AudioTrackPrivateAVFObjC.mm:
(WebCore::AudioTrackPrivateAVFObjC::resetPropertiesFromTrack):
* platform/graphics/avfoundation/objc/VideoTrackPrivateMediaSourceAVFObjC.mm:
(WebCore::VideoTrackPrivateMediaSourceAVFObjC::resetPropertiesFromTrack):

Rather than making allowing the AVPlayerItem to automatically select the "best"
AVMediaSelectionOption, select the automatic options when creating the AVPlayerItem
and thereafter allow the users manual selections "stick".

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::ensureAVPlayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::ensureAVPlayerItem):

Determine whether any MediaSelectionOptionsAVFObjC have been added or removed and send trackChange events accordingly.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::determineChangedTracksFromNewTracksAndOldItems): Added.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateAudioTracks): Search for updated selection options.
(WebCore::MediaPlayerPrivateAVFoundationObjC::updateVideoTracks): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::safeMediaSelectionGroupForAudibleMedia): Return selection group, if available.
(WebCore::MediaPlayerPrivateAVFoundationObjC::safeMediaSelectionGroupForVisualMedia): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksDidChange): Filter out AVPlayerItemTracks without
    AVAssetTracks, as these will be represented by MediaSelectionGroupObjCs instead.

Add new files to project.
* WebCore.xcodeproj/project.pbxproj:

LayoutTests:

* http/tests/media/hls/hls-audio-tracks-expected.txt: Added.
* http/tests/media/hls/hls-audio-tracks.html: Added.
* http/tests/media/resources/hls/audio-tracks.m3u8: Added.
* http/tests/media/resources/hls/bipbop/iframe_index.m3u8: Added.
* http/tests/media/resources/hls/bipbop/main0.ts: Added.
* http/tests/media/resources/hls/bipbop/main1.ts: Added.
* http/tests/media/resources/hls/bipbop/prog_index.m3u8: Added.
* http/tests/media/resources/hls/french/main.aac: Added.
* http/tests/media/resources/hls/french/prog_index.m3u8: Added.
* http/tests/media/resources/hls/spanish/main.aac: Added.
* http/tests/media/resources/hls/spanish/prog_index.m3u8: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@174823 268f45cc-cd09-0410-ab3c-d52691b4dbfc