| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "wtf/ArrayBufferView.h" | 29 #include "wtf/ArrayBufferView.h" |
| 30 #include "wtf/RefPtr.h" | 30 #include "wtf/RefPtr.h" |
| 31 | 31 |
| 32 namespace WTF { | 32 namespace WTF { |
| 33 | 33 |
| 34 bool ArrayBuffer::transfer(ArrayBufferContents& result) | 34 bool ArrayBuffer::transfer(ArrayBufferContents& result) |
| 35 { | 35 { |
| 36 RefPtr<ArrayBuffer> keepAlive(this); | 36 RefPtr<ArrayBuffer> keepAlive(this); |
| 37 | 37 |
| 38 if (!m_contents.data()) { | 38 if (!m_contents.data()) { |
| 39 result.clear(); | 39 result.neuter(); |
| 40 return false; | 40 return false; |
| 41 } | 41 } |
| 42 | 42 |
| 43 if (isShared()) { |
| 44 m_contents.transfer(result); |
| 45 // Return early to prevent neutering views when transferring |
| 46 // SharedArrayBuffers. |
| 47 return true; |
| 48 } |
| 49 |
| 43 bool allViewsAreNeuterable = true; | 50 bool allViewsAreNeuterable = true; |
| 44 for (ArrayBufferView* i = m_firstView; i; i = i->m_nextView) { | 51 for (ArrayBufferView* i = m_firstView; i; i = i->m_nextView) { |
| 45 if (!i->isNeuterable()) | 52 if (!i->isNeuterable()) |
| 46 allViewsAreNeuterable = false; | 53 allViewsAreNeuterable = false; |
| 47 } | 54 } |
| 48 | 55 |
| 49 if (allViewsAreNeuterable) { | 56 if (allViewsAreNeuterable) { |
| 50 m_contents.transfer(result); | 57 m_contents.transfer(result); |
| 58 m_contents.neuter(); |
| 51 } else { | 59 } else { |
| 52 m_contents.copyTo(result); | 60 m_contents.copyTo(result); |
| 53 if (!result.data()) | 61 if (!result.data()) |
| 54 return false; | 62 return false; |
| 55 } | 63 } |
| 56 | 64 |
| 57 while (m_firstView) { | 65 while (m_firstView) { |
| 58 ArrayBufferView* current = m_firstView; | 66 ArrayBufferView* current = m_firstView; |
| 59 removeView(current); | 67 removeView(current); |
| 60 if (allViewsAreNeuterable || current->isNeuterable()) | 68 if (allViewsAreNeuterable || current->isNeuterable()) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 82 if (view->m_nextView) | 90 if (view->m_nextView) |
| 83 view->m_nextView->m_prevView = view->m_prevView; | 91 view->m_nextView->m_prevView = view->m_prevView; |
| 84 if (view->m_prevView) | 92 if (view->m_prevView) |
| 85 view->m_prevView->m_nextView = view->m_nextView; | 93 view->m_prevView->m_nextView = view->m_nextView; |
| 86 if (m_firstView == view) | 94 if (m_firstView == view) |
| 87 m_firstView = view->m_nextView; | 95 m_firstView = view->m_nextView; |
| 88 view->m_prevView = view->m_nextView = 0; | 96 view->m_prevView = view->m_nextView = 0; |
| 89 } | 97 } |
| 90 | 98 |
| 91 } | 99 } |
| OLD | NEW |