Added missing tests.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of SourcePawn.
7 * SourcePawn is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * SourcePawn. If not, see http://www.gnu.org/licenses/.
20 #include "NativeTable.h"
21 #include "StringPool.h"
26 NativeTable::NativeTable(Zone *zone)
28 nativeMap_(ZoneAllocatorPolicy())
32 NativeTable::~NativeTable()
34 for (size_t i = 0; i < natives_.length(); i++)
39 NativeTable::initialize()
41 return nativeMap_.init(16);
45 NativeTable::add(Handle<String> name, size_t *indexp)
47 // :TODO: assert no GC
48 CharsAndLength key(name->chars(), name->length());
49 NativeMap::Insert p = nativeMap_.findForAdd(key);
51 *indexp = (*p)->index;
55 NativeInfo *info = new NativeInfo(name, NULL, natives_.length());
56 if (!info || !natives_.append(info))
59 if (!nativeMap_.add(p, info))
62 *indexp = info->index;
68 NativeTable::bind(const char *name, void *address)
70 CharsAndLength key(name, strlen(name));
71 NativeMap::Insert p = nativeMap_.findForAdd(key);
73 (*p)->address = address;
77 Local<String> str(zone_, zone_->symbols()->add(key.str(), key.length()));
81 // :TODO: assert no GC
82 NativeInfo *info = new NativeInfo(str, address, natives_.length());
83 if (!info || !natives_.append(info))
86 if (!nativeMap_.add(p, info))
93 NativeTable::accept(VirtualObjectVisitor *visitor)
95 for (size_t i = 0; i < natives_.length(); i++)
96 visitor->visit(natives_[i]->name.address());