/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: set ts=8 sts=2 et sw=2 tw=80: * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
class JSAPIRuntimeTest : public JSAPITest { public: static JSAPIRuntimeTest* list;
JSAPIRuntimeTest* next;
JSContext* cx;
JS::PersistentRootedObject global;
// Whether this test is willing to skip its init() and reuse a global (and // JSContext etc.) from a previous test that also has reuseGlobal=true. It // also means this test is willing to skip its uninit() if it is followed by // another reuseGlobal test. bool reuseGlobal;
JSAPIRuntimeTest() : JSAPITest(), cx(nullptr), reuseGlobal(false) {
next = list;
list = this;
}
// Initialize this test, possibly with the cx from a previously run test. bool init(JSContext* maybeReusedContext);
// If this test is ok with its cx and global being reused, release this // test's cx to be reused by another test.
JSContext* maybeForgetContext();
staticvoid MaybeFreeContext(JSContext* maybeCx);
// The real initialization happens in init(JSContext*), above, but this // method may be overridden to perform additional initialization after the // JSContext and global have been created. virtualbool init() { returntrue; } virtualvoid uninit();
virtualbool run(JS::HandleObject global) = 0;
#define EXEC(s) \ do { \ if (!exec(s, __FILE__, __LINE__)) returnfalse; \
} while (false)
bool exec(constchar* utf8, constchar* filename, int lineno);
// Like exec(), but doesn't call fail() if JS::Evaluate returns false. bool execDontReport(constchar* utf8, constchar* filename, int lineno);
#define EVAL(s, vp) \ do { \ if (!evaluate(s, __FILE__, __LINE__, vp)) returnfalse; \
} while (false)
bool evaluate(constchar* utf8, constchar* filename, int lineno,
JS::MutableHandleValue vp);
/* * A "fixture" is a subclass of JSAPIRuntimeTest that holds common definitions * for a set of tests. Each test that wants to use the fixture should use * BEGIN_FIXTURE_TEST and END_FIXTURE_TEST, just as one would use BEGIN_TEST and * END_TEST, but include the fixture class as the first argument. The fixture * class's declarations are then in scope for the test bodies.
*/
/* * A class for creating and managing one temporary file. * * We could use the ISO C temporary file functions here, but those try to * create files in the root directory on Windows, which fails for users * without Administrator privileges.
*/ class TempFile { constchar* name;
FILE* stream;
public:
TempFile() : name(), stream() {}
~TempFile() { if (stream) {
close();
} if (name) {
remove();
}
}
/* * Return a stream for a temporary file named |fileName|. Infallible. * Use only once per TempFile instance. If the file is not explicitly * closed and deleted via the member functions below, this object's * destructor will clean them up.
*/
FILE* open(constchar* fileName) {
stream = fopen(fileName, "wb+"); if (!stream) {
fprintf(stderr, "error opening temporary file '%s': %s\n", fileName,
strerror(errno)); exit(1);
}
name = fileName; return stream;
}
/* Close the temporary file's stream. */ void close() { if (fclose(stream) == EOF) {
fprintf(stderr, "error closing temporary file '%s': %s\n", name,
strerror(errno)); exit(1);
}
stream = nullptr;
}
/* Delete the temporary file. */ void remove() { if (::remove(name) != 0) {
fprintf(stderr, "error deleting temporary file '%s': %s\n", name,
strerror(errno)); exit(1);
}
name = nullptr;
}
};
// Just a wrapper around JSPrincipals that allows static construction. class TestJSPrincipals : public JSPrincipals { public: explicit TestJSPrincipals(int rc = 0) : JSPrincipals() { refcount = rc; }
// A class that simulates externally memory-managed data, for testing with // array buffers. class ExternalData { char* contents_;
size_t len_; bool uniquePointerCreated_ = false;
#ifdef JS_GC_ZEAL /* * Temporarily disable the GC zeal setting. This is only useful in tests that * need very explicit GC behavior and should not be used elsewhere.
*/ class AutoLeaveZeal {
JSContext* cx_;
uint32_t zealBits_;
uint32_t frequency_;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.