OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1886 | 1886 |
1887 SetUpFunction(); | 1887 SetUpFunction(); |
1888 | 1888 |
1889 | 1889 |
1890 //---------------------------------------------------------------------------- | 1890 //---------------------------------------------------------------------------- |
1891 | 1891 |
1892 // TODO(rossberg): very simple abstraction for generic microtask queue. | 1892 // TODO(rossberg): very simple abstraction for generic microtask queue. |
1893 // Eventually, we should move to a real event queue that allows to maintain | 1893 // Eventually, we should move to a real event queue that allows to maintain |
1894 // relative ordering of different kinds of tasks. | 1894 // relative ordering of different kinds of tasks. |
1895 | 1895 |
1896 function GetMicrotaskQueue() { | |
1897 var microtaskState = %GetMicrotaskState(); | |
1898 if (IS_UNDEFINED(microtaskState.queue)) { | |
1899 microtaskState.queue = new InternalArray; | |
1900 } | |
1901 return microtaskState.queue; | |
1902 } | |
1903 | |
1904 function RunMicrotasks() { | 1896 function RunMicrotasks() { |
1905 while (%SetMicrotaskPending(false)) { | 1897 while (%SetMicrotaskPending(false)) { |
1906 var microtaskState = %GetMicrotaskState(); | 1898 var microtaskState = %GetMicrotaskState(); |
1907 if (IS_UNDEFINED(microtaskState.queue)) | 1899 if (IS_UNDEFINED(microtaskState.queue)) |
1908 return; | 1900 return; |
1909 | 1901 |
1910 var microtasks = microtaskState.queue; | 1902 var microtasks = microtaskState.queue; |
1911 microtaskState.queue = new InternalArray; | 1903 delete microtaskState.queue; |
rafaelw
2014/04/28 05:09:34
nit: assign NULL here (and check for NULL as well
kouhei (in TOK)
2014/04/28 05:22:29
Sorry I reverted the change by mistake. Done.
| |
1912 | 1904 |
1913 for (var i = 0; i < microtasks.length; i++) { | 1905 for (var i = 0; i < microtasks.length; i++) { |
1914 microtasks[i](); | 1906 microtasks[i](); |
1915 } | 1907 } |
1916 } | 1908 } |
1917 } | 1909 } |
1918 | 1910 |
1919 function EnqueueExternalMicrotask(fn) { | 1911 function EnqueueMicrotask(fn) { |
1920 GetMicrotaskQueue().push(fn); | 1912 var microtaskState = %GetMicrotaskState(); |
1913 if (IS_UNDEFINED(microtaskState.queue)) { | |
1914 microtaskState.queue = new InternalArray; | |
1915 } | |
1916 microtaskState.queue.push(fn); | |
1921 %SetMicrotaskPending(true); | 1917 %SetMicrotaskPending(true); |
1922 } | 1918 } |
OLD | NEW |