AllocPolicy.cpp (1035B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * vim: set ts=8 sts=2 et sw=2 tw=80: 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "js/AllocPolicy.h" 8 9 #include "frontend/FrontendContext.h" // FrontendContext 10 #include "vm/JSContext.h" 11 12 using namespace js; 13 14 void* TempAllocPolicy::onOutOfMemory(arena_id_t arenaId, 15 AllocFunction allocFunc, size_t nbytes, 16 void* reallocPtr) { 17 void* result; 18 if (hasJSContext()) { 19 result = cx()->onOutOfMemory(allocFunc, arenaId, nbytes, reallocPtr); 20 } else { 21 result = fc()->onOutOfMemory(allocFunc, arenaId, nbytes, reallocPtr); 22 } 23 return result; 24 } 25 26 void TempAllocPolicy::reportAllocOverflow() const { 27 if (hasJSContext()) { 28 ReportAllocationOverflow(cx()); 29 } else { 30 ReportAllocationOverflow(fc()); 31 } 32 }