author | Birunthan Mohanathas <birunthan@mohanathas.com> |
Tue, 24 Sep 2013 22:59:40 -0400 | |
changeset 148618 | 0a28d2e865e47f512f34a038051fce2c7987731e |
parent 148617 | 1a4fdbcb1075ca3695e0ca95b78680d63fdcc4f3 |
child 148619 | 5d34afe94163e58ad32ded6f3bc47e3c389b1e60 |
push id | 25349 |
push user | ryanvm@gmail.com |
push date | Wed, 25 Sep 2013 18:52:12 +0000 |
treeherder | mozilla-central@39f30376058c [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | ehsan |
bugs | 784739 |
milestone | 27.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
--- a/js/src/ctypes/CTypes.cpp +++ b/js/src/ctypes/CTypes.cpp @@ -79,17 +79,17 @@ GetDeflatedUTF8StringLength(JSContext *m } } return nbytes; bad_surrogate: if (maybecx) { JS_snprintf(buffer, 10, "0x%x", c); JS_ReportErrorFlagsAndNumber(maybecx, JSREPORT_ERROR, js_GetErrorMessage, - NULL, JSMSG_BAD_SURROGATE_CHAR, buffer); + nullptr, JSMSG_BAD_SURROGATE_CHAR, buffer); } return (size_t) -1; } bool DeflateStringToUTF8Buffer(JSContext *maybecx, const jschar *src, size_t srclen, char *dst, size_t *dstlenp) { @@ -141,17 +141,17 @@ badSurrogate: /* Delegate error reporting to the measurement function. */ if (maybecx) GetDeflatedUTF8StringLength(maybecx, src - 1, srclen + 1); return false; bufferTooSmall: *dstlenp = (origDstlen - dstlen); if (maybecx) { - JS_ReportErrorNumber(maybecx, js_GetErrorMessage, NULL, + JS_ReportErrorNumber(maybecx, js_GetErrorMessage, nullptr, JSMSG_BUFFER_TOO_SMALL); } return false; } /******************************************************************************* ** JSAPI function prototypes *******************************************************************************/ @@ -178,17 +178,17 @@ namespace CType { static bool HasInstance(JSContext* cx, HandleObject obj, MutableHandleValue v, bool* bp); /* * Get the global "ctypes" object. * * |obj| must be a CType object. * - * This function never returns NULL. + * This function never returns nullptr. */ static JSObject* GetGlobalCTypes(JSContext* cx, JSObject* obj); } namespace ABI { bool IsABI(JSObject* obj); static bool ToSource(JSContext* cx, unsigned argc, jsval* vp); @@ -302,17 +302,17 @@ namespace CDataFinalizer { static bool Construct(JSContext* cx, unsigned argc, jsval *vp); /* * Private data held by |CDataFinalizer|. * * See also |enum CDataFinalizerSlot| for the slots of * |CDataFinalizer|. * - * Note: the private data may be NULL, if |dispose|, |forget| or the + * Note: the private data may be nullptr, if |dispose|, |forget| or the * finalizer has already been called. */ struct Private { /* * The C data to pass to the code. * Finalization/|dispose|/|forget| release this memory. */ void *cargs; @@ -358,33 +358,33 @@ namespace CDataFinalizer { */ static bool IsCDataFinalizer(JSObject *obj); /* * Clean up the finalization information of a CDataFinalizer. * * Used by |Finalize|, |Dispose| and |Forget|. * - * @param p The private information of the CDataFinalizer. If NULL, + * @param p The private information of the CDataFinalizer. If nullptr, * this function does nothing. - * @param obj Either NULL, if the object should not be cleaned up (i.e. - * during finalization) or a CDataFinalizer JSObject. Always use NULL + * @param obj Either nullptr, if the object should not be cleaned up (i.e. + * during finalization) or a CDataFinalizer JSObject. Always use nullptr * if you are calling from a finalizer. */ static void Cleanup(Private *p, JSObject *obj); /* * Perform the actual call to the finalizer code. */ static void CallFinalizer(CDataFinalizer::Private *p, int* errnoStatus, int32_t* lastErrorStatus); /* - * Return the CType of a CDataFinalizer object, or NULL if the object + * Return the CType of a CDataFinalizer object, or nullptr if the object * has been cleaned-up already. */ static JSObject *GetCType(JSContext *cx, JSObject *obj); /* * Perform finalization of a |CDataFinalizer| */ static void Finalize(JSFreeOp *fop, JSObject *obj); @@ -462,52 +462,52 @@ static const JSClass sCABIClass = { // Class representing ctypes.{C,Pointer,Array,Struct,Function}Type.prototype. // This exists to give said prototypes a class of "CType", and to provide // reserved slots for stashing various other prototype objects. static const JSClass sCTypeProtoClass = { "CType", JSCLASS_HAS_RESERVED_SLOTS(CTYPEPROTO_SLOTS), JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, - JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, NULL, - NULL, ConstructAbstract, NULL, ConstructAbstract + JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, nullptr, + nullptr, ConstructAbstract, nullptr, ConstructAbstract }; // Class representing ctypes.CData.prototype and the 'prototype' properties // of CTypes. This exists to give said prototypes a class of "CData". static const JSClass sCDataProtoClass = { "CData", 0, JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub }; static const JSClass sCTypeClass = { "CType", JSCLASS_IMPLEMENTS_BARRIERS | JSCLASS_HAS_RESERVED_SLOTS(CTYPE_SLOTS), JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, CType::Finalize, - NULL, CType::ConstructData, CType::HasInstance, CType::ConstructData, + nullptr, CType::ConstructData, CType::HasInstance, CType::ConstructData, CType::Trace }; static const JSClass sCDataClass = { "CData", JSCLASS_HAS_RESERVED_SLOTS(CDATA_SLOTS), JS_PropertyStub, JS_DeletePropertyStub, ArrayType::Getter, ArrayType::Setter, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, CData::Finalize, - NULL, FunctionType::Call, NULL, FunctionType::Call + nullptr, FunctionType::Call, nullptr, FunctionType::Call }; static const JSClass sCClosureClass = { "CClosure", JSCLASS_IMPLEMENTS_BARRIERS | JSCLASS_HAS_RESERVED_SLOTS(CCLOSURE_SLOTS), JS_PropertyStub, JS_DeletePropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, CClosure::Finalize, - NULL, NULL, NULL, NULL, CClosure::Trace + nullptr, nullptr, nullptr, nullptr, CClosure::Trace }; /* * Class representing the prototype of CDataFinalizer. */ static const JSClass sCDataFinalizerProtoClass = { "CDataFinalizer", 0, @@ -794,17 +794,17 @@ static const JSErrorFormatString ErrorFo #undef MSG_DEF }; static const JSErrorFormatString* GetErrorMessage(void* userRef, const char* locale, const unsigned errorNumber) { if (0 < errorNumber && errorNumber < CTYPESERR_LIMIT) return &ErrorFormatString[errorNumber]; - return NULL; + return nullptr; } static bool TypeError(JSContext* cx, const char* expected, jsval actual) { JSString* str = JS_ValueToSource(cx, actual); JSAutoByteString bytes; @@ -812,113 +812,113 @@ TypeError(JSContext* cx, const char* exp if (str) { src = bytes.encodeLatin1(cx, str); if (!src) return false; } else { JS_ClearPendingException(cx); src = "<<error converting value to string>>"; } - JS_ReportErrorNumber(cx, GetErrorMessage, NULL, + JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, CTYPESMSG_TYPE_ERROR, expected, src); return false; } static JSObject* InitCTypeClass(JSContext* cx, HandleObject parent) { JSFunction *fun = JS_DefineFunction(cx, parent, "CType", ConstructAbstract, 0, CTYPESCTOR_FLAGS); if (!fun) - return NULL; + return nullptr; RootedObject ctor(cx, JS_GetFunctionObject(fun)); RootedObject fnproto(cx); if (!JS_GetPrototype(cx, ctor, &fnproto)) - return NULL; + return nullptr; JS_ASSERT(ctor); JS_ASSERT(fnproto); // Set up ctypes.CType.prototype. RootedObject prototype(cx, JS_NewObject(cx, &sCTypeProtoClass, fnproto, parent)); if (!prototype) - return NULL; + return nullptr; if (!JS_DefineProperty(cx, ctor, "prototype", OBJECT_TO_JSVAL(prototype), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) - return NULL; + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + return nullptr; if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(ctor), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) - return NULL; + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + return nullptr; // Define properties and functions common to all CTypes. if (!JS_DefineProperties(cx, prototype, sCTypeProps) || !JS_DefineFunctions(cx, prototype, sCTypeFunctions)) - return NULL; + return nullptr; if (!JS_FreezeObject(cx, ctor) || !JS_FreezeObject(cx, prototype)) - return NULL; + return nullptr; return prototype; } static JSObject* InitABIClass(JSContext* cx, JSObject* parent) { - RootedObject obj(cx, JS_NewObject(cx, NULL, NULL, NULL)); + RootedObject obj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); if (!obj) - return NULL; + return nullptr; if (!JS_DefineFunctions(cx, obj, sCABIFunctions)) - return NULL; + return nullptr; return obj; } static JSObject* InitCDataClass(JSContext* cx, HandleObject parent, HandleObject CTypeProto) { JSFunction* fun = JS_DefineFunction(cx, parent, "CData", ConstructAbstract, 0, CTYPESCTOR_FLAGS); if (!fun) - return NULL; + return nullptr; RootedObject ctor(cx, JS_GetFunctionObject(fun)); JS_ASSERT(ctor); // Set up ctypes.CData.__proto__ === ctypes.CType.prototype. // (Note that 'ctypes.CData instanceof Function' is still true, thanks to the // prototype chain.) if (!JS_SetPrototype(cx, ctor, CTypeProto)) - return NULL; + return nullptr; // Set up ctypes.CData.prototype. - RootedObject prototype(cx, JS_NewObject(cx, &sCDataProtoClass, NULL, parent)); + RootedObject prototype(cx, JS_NewObject(cx, &sCDataProtoClass, nullptr, parent)); if (!prototype) - return NULL; + return nullptr; if (!JS_DefineProperty(cx, ctor, "prototype", OBJECT_TO_JSVAL(prototype), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) - return NULL; + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + return nullptr; if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(ctor), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) - return NULL; + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + return nullptr; // Define properties and functions common to all CDatas. if (!JS_DefineProperties(cx, prototype, sCDataProps) || !JS_DefineFunctions(cx, prototype, sCDataFunctions)) - return NULL; + return nullptr; if (//!JS_FreezeObject(cx, prototype) || // XXX fixme - see bug 541212! !JS_FreezeObject(cx, ctor)) - return NULL; + return nullptr; return prototype; } static bool DefineABIConstant(JSContext* cx, HandleObject parent, const char* name, @@ -959,27 +959,27 @@ InitTypeConstructor(JSContext* cx, // Set up the .prototype and .prototype.constructor properties. typeProto.set(JS_NewObject(cx, &sCTypeProtoClass, CTypeProto, parent)); if (!typeProto) return false; // Define property before proceeding, for GC safety. if (!JS_DefineProperty(cx, obj, "prototype", OBJECT_TO_JSVAL(typeProto), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; if (fns && !JS_DefineFunctions(cx, typeProto, fns)) return false; if (!JS_DefineProperties(cx, typeProto, props)) return false; if (!JS_DefineProperty(cx, typeProto, "constructor", OBJECT_TO_JSVAL(obj), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; // Stash ctypes.{Pointer,Array,Struct}Type.prototype on a reserved slot of // the type constructor, for faster lookup. js::SetFunctionNativeReserved(obj, SLOT_FN_CTORPROTO, OBJECT_TO_JSVAL(typeProto)); // Create an object to serve as the common ancestor for all CData objects // created from the given type constructor. This has ctypes.CData.prototype @@ -1013,41 +1013,41 @@ static JSObject* InitInt64Class(JSContext* cx, HandleObject parent, const JSClass* clasp, JSNative construct, const JSFunctionSpec* fs, const JSFunctionSpec* static_fs) { // Init type class and constructor - RootedObject prototype(cx, JS_InitClass(cx, parent, NULL, clasp, construct, - 0, NULL, fs, NULL, static_fs)); + RootedObject prototype(cx, JS_InitClass(cx, parent, nullptr, clasp, construct, + 0, nullptr, fs, nullptr, static_fs)); if (!prototype) - return NULL; + return nullptr; RootedObject ctor(cx, JS_GetConstructor(cx, prototype)); if (!ctor) - return NULL; + return nullptr; if (!JS_FreezeObject(cx, ctor)) - return NULL; + return nullptr; // Redefine the 'join' function as an extended native and stash // ctypes.{Int64,UInt64}.prototype in a reserved slot of the new function. JS_ASSERT(clasp == &sInt64ProtoClass || clasp == &sUInt64ProtoClass); JSNative native = (clasp == &sInt64ProtoClass) ? Int64::Join : UInt64::Join; JSFunction* fun = js::DefineFunctionWithReserved(cx, ctor, "join", native, 2, CTYPESFN_FLAGS); if (!fun) - return NULL; + return nullptr; js::SetFunctionNativeReserved(fun, SLOT_FN_INT64PROTO, OBJECT_TO_JSVAL(prototype)); if (!JS_FreezeObject(cx, prototype)) - return NULL; + return nullptr; return prototype; } static void AttachProtos(JSObject* proto, const AutoObjectVector& protos) { // For a given 'proto' of [[Class]] "CTypeProto", attach each of the 'protos' @@ -1119,35 +1119,35 @@ InitTypeClasses(JSContext* cx, HandleObj // binary data of the given type. // * 'prototype' property: // * [[Class]] "CDataProto" // * __proto__ === 'p', the prototype object from above // * 'constructor' property === 't' AutoObjectVector protos(cx); protos.resize(CTYPEPROTO_SLOTS); if (!InitTypeConstructor(cx, parent, CTypeProto, CDataProto, - sPointerFunction, NULL, sPointerProps, + sPointerFunction, nullptr, sPointerProps, sPointerInstanceFunctions, sPointerInstanceProps, protos.handleAt(SLOT_POINTERPROTO), protos.handleAt(SLOT_POINTERDATAPROTO))) return false; if (!InitTypeConstructor(cx, parent, CTypeProto, CDataProto, - sArrayFunction, NULL, sArrayProps, + sArrayFunction, nullptr, sArrayProps, sArrayInstanceFunctions, sArrayInstanceProps, protos.handleAt(SLOT_ARRAYPROTO), protos.handleAt(SLOT_ARRAYDATAPROTO))) return false; if (!InitTypeConstructor(cx, parent, CTypeProto, CDataProto, sStructFunction, sStructFunctions, sStructProps, - sStructInstanceFunctions, NULL, + sStructInstanceFunctions, nullptr, protos.handleAt(SLOT_STRUCTPROTO), protos.handleAt(SLOT_STRUCTDATAPROTO))) return false; if (!InitTypeConstructor(cx, parent, CTypeProto, protos.handleAt(SLOT_POINTERDATAPROTO), - sFunctionFunction, NULL, sFunctionProps, sFunctionInstanceFunctions, NULL, + sFunctionFunction, nullptr, sFunctionProps, sFunctionInstanceFunctions, nullptr, protos.handleAt(SLOT_FUNCTIONPROTO), protos.handleAt(SLOT_FUNCTIONDATAPROTO))) return false; protos[SLOT_CDATAPROTO] = CDataProto; // Create and attach the ctypes.{Int64,UInt64} constructors. // Each of these has, respectively: // * [[Class]] "Function" @@ -1205,32 +1205,32 @@ InitTypeClasses(JSContext* cx, HandleObj INT_TO_JSVAL(ffiType.alignment), &ffiType)); \ if (!typeObj_##name) \ return false; #include "ctypes/typedefs.h" // Alias 'ctypes.unsigned' as 'ctypes.unsigned_int', since they represent // the same type in C. if (!JS_DefineProperty(cx, parent, "unsigned", - OBJECT_TO_JSVAL(typeObj_unsigned_int), NULL, NULL, + OBJECT_TO_JSVAL(typeObj_unsigned_int), nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; // Create objects representing the special types void_t and voidptr_t. RootedObject typeObj(cx, CType::DefineBuiltin(cx, parent, "void_t", CTypeProto, CDataProto, "void", TYPE_void_t, JSVAL_VOID, JSVAL_VOID, &ffi_type_void)); if (!typeObj) return false; typeObj = PointerType::CreateInternal(cx, typeObj); if (!typeObj) return false; if (!JS_DefineProperty(cx, parent, "voidptr_t", OBJECT_TO_JSVAL(typeObj), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; return true; } bool IsCTypesGlobal(JSObject* obj) { @@ -1240,17 +1240,17 @@ IsCTypesGlobal(JSObject* obj) // Get the JSCTypesCallbacks struct from the 'ctypes' object 'obj'. JSCTypesCallbacks* GetCallbacks(JSObject* obj) { JS_ASSERT(IsCTypesGlobal(obj)); jsval result = JS_GetReservedSlot(obj, SLOT_CALLBACKS); if (JSVAL_IS_VOID(result)) - return NULL; + return nullptr; return static_cast<JSCTypesCallbacks*>(JSVAL_TO_PRIVATE(result)); } // Utility function to access a property of an object as an object // returns false and sets the error if the property does not exist // or is not an object static bool GetObjectProperty(JSContext *cx, HandleObject obj, @@ -1277,17 +1277,17 @@ using namespace js; using namespace js::ctypes; JS_PUBLIC_API(bool) JS_InitCTypesClass(JSContext* cx, JSObject *globalArg) { RootedObject global(cx, globalArg); // attach ctypes property to global object - RootedObject ctypes(cx, JS_NewObject(cx, &sCTypesGlobalClass, NULL, NULL)); + RootedObject ctypes(cx, JS_NewObject(cx, &sCTypesGlobalClass, nullptr, nullptr)); if (!ctypes) return false; if (!JS_DefineProperty(cx, global, "ctypes", OBJECT_TO_JSVAL(ctypes), JS_PropertyStub, JS_StrictPropertyStub, JSPROP_READONLY | JSPROP_PERMANENT)){ return false; } @@ -1299,30 +1299,30 @@ JS_InitCTypesClass(JSContext* cx, JSObje !JS_DefineProperties(cx, ctypes, sModuleProps)) return false; // Set up ctypes.CDataFinalizer.prototype. RootedObject ctor(cx); if (!GetObjectProperty(cx, ctypes, "CDataFinalizer", &ctor)) return false; - RootedObject prototype(cx, JS_NewObject(cx, &sCDataFinalizerProtoClass, NULL, ctypes)); + RootedObject prototype(cx, JS_NewObject(cx, &sCDataFinalizerProtoClass, nullptr, ctypes)); if (!prototype) return false; if (!JS_DefineProperties(cx, prototype, sCDataFinalizerProps) || !JS_DefineFunctions(cx, prototype, sCDataFinalizerFunctions)) return false; if (!JS_DefineProperty(cx, ctor, "prototype", OBJECT_TO_JSVAL(prototype), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(ctor), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; // Seal the ctypes object, to prevent modification. return JS_FreezeObject(cx, ctypes); } JS_PUBLIC_API(void) @@ -1704,17 +1704,17 @@ jsvalToFloat(JSContext *cx, jsval val, F } template<class IntegerType> static bool StringToInteger(JSContext* cx, JSString* string, IntegerType* result) { JS_STATIC_ASSERT(numeric_limits<IntegerType>::is_exact); - const jschar* cp = string->getChars(NULL); + const jschar* cp = string->getChars(nullptr); if (!cp) return false; const jschar* end = cp + string->length(); if (cp == end) return false; IntegerType sign = 1; @@ -2195,19 +2195,19 @@ ImplicitConvert(JSContext* cx, bool isArgument, bool* freePointer) { RootedObject targetType(cx, targetType_); JS_ASSERT(CType::IsSizeDefined(targetType)); // First, check if val is either a CData object or a CDataFinalizer // of type targetType. - JSObject* sourceData = NULL; - JSObject* sourceType = NULL; - RootedObject valObj(cx, NULL); + JSObject* sourceData = nullptr; + JSObject* sourceType = nullptr; + RootedObject valObj(cx, nullptr); if (!JSVAL_IS_PRIMITIVE(val)) { valObj = JSVAL_TO_OBJECT(val); if (CData::IsCData(valObj)) { sourceData = valObj; sourceType = CData::GetCType(sourceData); // If the types are equal, copy the buffer contained within the CData. // (Note that the buffers may overlap partially or completely.) @@ -2286,17 +2286,17 @@ ImplicitConvert(JSContext* cx, } \ *static_cast<type*>(buffer) = result; \ break; \ } #include "ctypes/typedefs.h" case TYPE_pointer: { if (JSVAL_IS_NULL(val)) { // Convert to a null pointer. - *static_cast<void**>(buffer) = NULL; + *static_cast<void**>(buffer) = nullptr; break; } JS::Rooted<JSObject*> baseType(cx, PointerType::GetBaseType(targetType)); if (sourceData) { // First, determine if the targetType is ctypes.void_t.ptr. TypeCode sourceCode = CType::GetTypeCode(sourceType); void* sourceBuffer = CData::GetData(sourceData); @@ -2461,17 +2461,17 @@ ImplicitConvert(JSContext* cx, } for (uint32_t i = 0; i < sourceLength; ++i) { RootedValue item(cx); if (!JS_GetElement(cx, valObj, i, &item)) return false; char* data = intermediate.get() + elementSize * i; - if (!ImplicitConvert(cx, item, baseType, data, false, NULL)) + if (!ImplicitConvert(cx, item, baseType, data, false, nullptr)) return false; } memcpy(buffer, intermediate.get(), arraySize); } else if (!JSVAL_IS_PRIMITIVE(val) && JS_IsArrayBufferObject(valObj)) { // Check that array is consistent with type, then @@ -2544,17 +2544,17 @@ ImplicitConvert(JSContext* cx, return false; RootedValue prop(cx); if (!JS_GetPropertyById(cx, valObj, id, &prop)) return false; // Convert the field via ImplicitConvert(). char* fieldData = intermediate.get() + field->mOffset; - if (!ImplicitConvert(cx, prop, field->mType, fieldData, false, NULL)) + if (!ImplicitConvert(cx, prop, field->mType, fieldData, false, nullptr)) return false; ++i; } const FieldInfoHash* fields = StructType::GetFieldInfo(targetType); if (i != fields->count()) { JS_ReportError(cx, "missing fields"); @@ -2577,17 +2577,17 @@ ImplicitConvert(JSContext* cx, // Convert jsval 'val' to a C binary representation of CType 'targetType', // storing the result in 'buffer'. This function is more forceful than // ImplicitConvert. static bool ExplicitConvert(JSContext* cx, HandleValue val, HandleObject targetType, void* buffer) { // If ImplicitConvert succeeds, use that result. - if (ImplicitConvert(cx, val, targetType, buffer, false, NULL)) + if (ImplicitConvert(cx, val, targetType, buffer, false, nullptr)) return true; // If ImplicitConvert failed, and there is no pending exception, then assume // hard failure (out of memory, or some other similarly serious condition). // We store any pending exception in case we need to re-throw it. RootedValue ex(cx); if (!JS_GetPendingException(cx, &ex)) return false; @@ -3122,17 +3122,17 @@ CType::ConstructBasic(JSContext* cx, const CallArgs& args) { if (args.length() > 1) { JS_ReportError(cx, "CType constructor takes zero or one argument"); return false; } // construct a CData object - RootedObject result(cx, CData::Create(cx, obj, NullPtr(), NULL, true)); + RootedObject result(cx, CData::Create(cx, obj, NullPtr(), nullptr, true)); if (!result) return false; if (args.length() == 1) { if (!ExplicitConvert(cx, args[0], obj, CData::GetData(result))) return false; } @@ -3169,45 +3169,45 @@ CType::Create(JSContext* cx, // functions common to all CData objects of types derived from // 'typeProto'. (For instance, this could be ctypes.CData.prototype // for simple types, or something representing structs for StructTypes.) // * 'constructor' property === 't' // * Additional properties specified by 'ps', as appropriate for the // specific type instance 't'. RootedObject typeObj(cx, JS_NewObject(cx, &sCTypeClass, typeProto, parent)); if (!typeObj) - return NULL; + return nullptr; // Set up the reserved slots. JS_SetReservedSlot(typeObj, SLOT_TYPECODE, INT_TO_JSVAL(type)); if (ffiType) JS_SetReservedSlot(typeObj, SLOT_FFITYPE, PRIVATE_TO_JSVAL(ffiType)); if (name) JS_SetReservedSlot(typeObj, SLOT_NAME, STRING_TO_JSVAL(name)); JS_SetReservedSlot(typeObj, SLOT_SIZE, size); JS_SetReservedSlot(typeObj, SLOT_ALIGN, align); if (dataProto) { // Set up the 'prototype' and 'prototype.constructor' properties. RootedObject prototype(cx, JS_NewObject(cx, &sCDataProtoClass, dataProto, parent)); if (!prototype) - return NULL; + return nullptr; if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(typeObj), - NULL, NULL, JSPROP_READONLY | JSPROP_PERMANENT)) - return NULL; + nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT)) + return nullptr; // Set the 'prototype' object. //if (!JS_FreezeObject(cx, prototype)) // XXX fixme - see bug 541212! - // return NULL; + // return nullptr; JS_SetReservedSlot(typeObj, SLOT_PROTO, OBJECT_TO_JSVAL(prototype)); } if (!JS_FreezeObject(cx, typeObj)) - return NULL; + return nullptr; // Assert a sanity check on size and alignment: size % alignment should always // be zero. JS_ASSERT_IF(IsSizeDefined(typeObj), GetSize(typeObj) % GetAlignment(typeObj) == 0); return typeObj; } @@ -3227,27 +3227,27 @@ CType::DefineBuiltin(JSContext* cx, RootedObject parent(cx, parent_); RootedObject typeProto(cx, typeProto_); RootedObject dataProto(cx, dataProto_); RootedValue size(cx, size_); RootedValue align(cx, align_); RootedString nameStr(cx, JS_NewStringCopyZ(cx, name)); if (!nameStr) - return NULL; + return nullptr; // Create a new CType object with the common properties and slots. RootedObject typeObj(cx, Create(cx, typeProto, dataProto, type, nameStr, size, align, ffiType)); if (!typeObj) - return NULL; + return nullptr; // Define the CType as a 'propName' property on 'parent'. if (!JS_DefineProperty(cx, parent, propName, OBJECT_TO_JSVAL(typeObj), - NULL, NULL, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) - return NULL; + nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) + return nullptr; return typeObj; } void CType::Finalize(JSFreeOp *fop, JSObject* obj) { // Make sure our TypeCode slot is legit. If it's not, bail. @@ -3514,34 +3514,34 @@ CType::GetFFIType(JSContext* cx, JSObjec result = StructType::BuildFFIType(cx, obj); break; default: MOZ_ASSUME_UNREACHABLE("simple types must have an ffi_type"); } if (!result) - return NULL; + return nullptr; JS_SetReservedSlot(obj, SLOT_FFITYPE, PRIVATE_TO_JSVAL(result.get())); return result.forget(); } JSString* CType::GetName(JSContext* cx, HandleObject obj) { JS_ASSERT(CType::IsCType(obj)); jsval string = JS_GetReservedSlot(obj, SLOT_NAME); if (!JSVAL_IS_VOID(string)) return JSVAL_TO_STRING(string); // Build the type name lazily. JSString* name = BuildTypeName(cx, obj); if (!name) - return NULL; + return nullptr; JS_SetReservedSlot(obj, SLOT_NAME, STRING_TO_JSVAL(name)); return name; } JSObject* CType::GetProtoFromCtor(JSObject* obj, CTypeProtoSlot slot) { // Get ctypes.{Pointer,Array,Struct}Type.prototype from a reserved slot @@ -3560,17 +3560,17 @@ JSObject* CType::GetProtoFromType(JSContext* cx, JSObject* objArg, CTypeProtoSlot slot) { JS_ASSERT(IsCType(objArg)); RootedObject obj(cx, objArg); // Get the prototype of the type object. RootedObject proto(cx); if (!JS_GetPrototype(cx, obj, &proto)) - return NULL; + return nullptr; JS_ASSERT(proto); JS_ASSERT(CType::IsCTypeProto(proto)); // Get the requested ctypes.{Pointer,Array,Struct,Function}Type.prototype. jsval result = JS_GetReservedSlot(proto, slot); JS_ASSERT(!JSVAL_IS_PRIMITIVE(result)); return JSVAL_TO_OBJECT(result); } @@ -3760,17 +3760,17 @@ CType::HasInstance(JSContext* cx, Handle static JSObject* CType::GetGlobalCTypes(JSContext* cx, JSObject* objArg) { JS_ASSERT(CType::IsCType(objArg)); RootedObject obj(cx, objArg); RootedObject objTypeProto(cx); if (!JS_GetPrototype(cx, obj, &objTypeProto)) - return NULL; + return nullptr; JS_ASSERT(objTypeProto); JS_ASSERT(CType::IsCTypeProto(objTypeProto)); jsval valCTypes = JS_GetReservedSlot(objTypeProto, SLOT_CTYPES); JS_ASSERT(!JSVAL_IS_PRIMITIVE(valCTypes)); JS_ASSERT(!JSVAL_IS_PRIMITIVE(valCTypes)); return &valCTypes.toObject(); @@ -3864,28 +3864,28 @@ PointerType::CreateInternal(JSContext* c return &slot.toObject(); // Get ctypes.PointerType.prototype and the common prototype for CData objects // of this type, or ctypes.FunctionType.prototype for function pointers. CTypeProtoSlot slotId = CType::GetTypeCode(baseType) == TYPE_function ? SLOT_FUNCTIONDATAPROTO : SLOT_POINTERDATAPROTO; RootedObject dataProto(cx, CType::GetProtoFromType(cx, baseType, slotId)); if (!dataProto) - return NULL; + return nullptr; RootedObject typeProto(cx, CType::GetProtoFromType(cx, baseType, SLOT_POINTERPROTO)); if (!typeProto) - return NULL; + return nullptr; // Create a new CType object with the common properties and slots. JSObject* typeObj = CType::Create(cx, typeProto, dataProto, TYPE_pointer, - NULL, INT_TO_JSVAL(sizeof(void*)), + nullptr, INT_TO_JSVAL(sizeof(void*)), INT_TO_JSVAL(ffi_type_pointer.alignment), &ffi_type_pointer); if (!typeObj) - return NULL; + return nullptr; // Set the target type. (This will be 'null' for an opaque pointer type.) JS_SetReservedSlot(typeObj, SLOT_TARGET_T, OBJECT_TO_JSVAL(baseType)); // Finally, cache our newly-created PointerType on our pointed-to CType. JS_SetReservedSlot(baseType, SLOT_PTR, OBJECT_TO_JSVAL(typeObj)); return typeObj; @@ -3901,17 +3901,17 @@ PointerType::ConstructData(JSContext* cx return false; } if (args.length() > 3) { JS_ReportError(cx, "constructor takes 0, 1, 2, or 3 arguments"); return false; } - RootedObject result(cx, CData::Create(cx, obj, NullPtr(), NULL, true)); + RootedObject result(cx, CData::Create(cx, obj, NullPtr(), nullptr, true)); if (!result) return false; // Set return value early, must not observe *vp after args.rval().setObject(*result); // There are 3 things that we might be creating here: // 1 - A null pointer (no arguments) @@ -3946,20 +3946,20 @@ PointerType::ConstructData(JSContext* cx // // Case 3 - Closure // // The second argument is an optional 'this' parameter with which to invoke // the given js function. Callers may leave this blank, or pass null if they // wish to pass the third argument. - RootedObject thisObj(cx, NULL); + RootedObject thisObj(cx, nullptr); if (args.length() >= 2) { if (args[1].isNull()) { - thisObj = NULL; + thisObj = nullptr; } else if (!JSVAL_IS_PRIMITIVE(args[1])) { thisObj = &args[1].toObject(); } else if (!JS_ValueToObject(cx, args[1], &thisObj)) { return false; } } // The third argument is an optional error sentinel that js-ctypes will return @@ -4014,17 +4014,17 @@ PointerType::IsNull(JSContext* cx, unsig // Get pointer type and base type. JSObject* typeObj = CData::GetCType(obj); if (CType::GetTypeCode(typeObj) != TYPE_pointer) { JS_ReportError(cx, "not a PointerType"); return false; } void* data = *static_cast<void**>(CData::GetData(obj)); - args.rval().setBoolean(data == NULL); + args.rval().setBoolean(data == nullptr); return true; } bool PointerType::OffsetBy(JSContext* cx, const CallArgs& args, int offset) { JSObject* obj = JS_THIS_OBJECT(cx, args.base()); if (!obj) @@ -4093,17 +4093,17 @@ PointerType::ContentsGetter(JSContext* c RootedObject baseType(cx, GetBaseType(typeObj)); if (!CType::IsSizeDefined(baseType)) { JS_ReportError(cx, "cannot get contents of undefined size"); return false; } void* data = *static_cast<void**>(CData::GetData(obj)); - if (data == NULL) { + if (data == nullptr) { JS_ReportError(cx, "cannot read contents of null pointer"); return false; } RootedValue result(cx); if (!ConvertToJS(cx, baseType, NullPtr(), data, false, false, result.address())) return false; @@ -4132,22 +4132,22 @@ PointerType::ContentsSetter(JSContext* c JSObject* baseType = GetBaseType(typeObj); if (!CType::IsSizeDefined(baseType)) { JS_ReportError(cx, "cannot set contents of undefined size"); return false; } void* data = *static_cast<void**>(CData::GetData(obj)); - if (data == NULL) { + if (data == nullptr) { JS_ReportError(cx, "cannot write contents to null pointer"); return false; } - return ImplicitConvert(cx, vp, baseType, data, false, NULL); + return ImplicitConvert(cx, vp, baseType, data, false, nullptr); } /******************************************************************************* ** ArrayType implementation *******************************************************************************/ bool ArrayType::Create(JSContext* cx, unsigned argc, jsval* vp) @@ -4186,51 +4186,51 @@ ArrayType::CreateInternal(JSContext* cx, HandleObject baseType, size_t length, bool lengthDefined) { // Get ctypes.ArrayType.prototype and the common prototype for CData objects // of this type, from ctypes.CType.prototype. RootedObject typeProto(cx, CType::GetProtoFromType(cx, baseType, SLOT_ARRAYPROTO)); if (!typeProto) - return NULL; + return nullptr; RootedObject dataProto(cx, CType::GetProtoFromType(cx, baseType, SLOT_ARRAYDATAPROTO)); if (!dataProto) - return NULL; + return nullptr; // Determine the size of the array from the base type, if possible. // The size of the base type must be defined. // If our length is undefined, both our size and length will be undefined. size_t baseSize; if (!CType::GetSafeSize(baseType, &baseSize)) { JS_ReportError(cx, "base size must be defined"); - return NULL; + return nullptr; } RootedValue sizeVal(cx, JSVAL_VOID); RootedValue lengthVal(cx, JSVAL_VOID); if (lengthDefined) { // Check for overflow, and convert to an int or double as required. size_t size = length * baseSize; if (length > 0 && size / length != baseSize) { JS_ReportError(cx, "size overflow"); - return NULL; + return nullptr; } if (!SizeTojsval(cx, size, sizeVal.address()) || !SizeTojsval(cx, length, lengthVal.address())) - return NULL; + return nullptr; } size_t align = CType::GetAlignment(baseType); // Create a new CType object with the common properties and slots. - JSObject* typeObj = CType::Create(cx, typeProto, dataProto, TYPE_array, NULL, - sizeVal, INT_TO_JSVAL(align), NULL); + JSObject* typeObj = CType::Create(cx, typeProto, dataProto, TYPE_array, nullptr, + sizeVal, INT_TO_JSVAL(align), nullptr); if (!typeObj) - return NULL; + return nullptr; // Set the element type. JS_SetReservedSlot(typeObj, SLOT_ELEMENT_T, OBJECT_TO_JSVAL(baseType)); // Set the length. JS_SetReservedSlot(typeObj, SLOT_LENGTH, lengthVal); return typeObj; @@ -4318,17 +4318,17 @@ ArrayType::ConstructData(JSContext* cx, } // Construct a new ArrayType of defined length, for the new CData object. obj = CreateInternal(cx, baseType, length, true); if (!obj) return false; } - JSObject* result = CData::Create(cx, obj, NullPtr(), NULL, true); + JSObject* result = CData::Create(cx, obj, NullPtr(), nullptr, true); if (!result) return false; args.rval().setObject(*result); if (convertObject) { if (!ExplicitConvert(cx, args[0], obj, CData::GetData(result))) return false; @@ -4394,45 +4394,45 @@ ArrayType::BuildFFIType(JSContext* cx, J { JS_ASSERT(CType::IsCType(obj)); JS_ASSERT(CType::GetTypeCode(obj) == TYPE_array); JS_ASSERT(CType::IsSizeDefined(obj)); JSObject* baseType = ArrayType::GetBaseType(obj); ffi_type* ffiBaseType = CType::GetFFIType(cx, baseType); if (!ffiBaseType) - return NULL; + return nullptr; size_t length = ArrayType::GetLength(obj); // Create an ffi_type to represent the array. This is necessary for the case // where the array is part of a struct. Since libffi has no intrinsic // support for array types, we approximate it by creating a struct type // with elements of type 'baseType' and with appropriate size and alignment // values. It would be nice to not do all the work of setting up 'elements', // but some libffi platforms currently require that it be meaningful. I'm // looking at you, x86_64. AutoPtr<ffi_type> ffiType(cx->new_<ffi_type>()); if (!ffiType) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } ffiType->type = FFI_TYPE_STRUCT; ffiType->size = CType::GetSize(obj); ffiType->alignment = CType::GetAlignment(obj); ffiType->elements = cx->pod_malloc<ffi_type*>(length + 1); if (!ffiType->elements) { JS_ReportAllocationOverflow(cx); - return NULL; + return nullptr; } for (size_t i = 0; i < length; ++i) ffiType->elements[i] = ffiBaseType; - ffiType->elements[length] = NULL; + ffiType->elements[length] = nullptr; return ffiType.forget(); } bool ArrayType::ElementTypeGetter(JSContext* cx, HandleObject obj, HandleId idval, MutableHandleValue vp) { if (!CType::IsCType(obj) || CType::GetTypeCode(obj) != TYPE_array) { @@ -4529,17 +4529,17 @@ ArrayType::Setter(JSContext* cx, HandleO if (!ok || index >= length) { JS_ReportError(cx, "invalid index"); return false; } JSObject* baseType = GetBaseType(typeObj); size_t elementSize = CType::GetSize(baseType); char* data = static_cast<char*>(CData::GetData(obj)) + elementSize * index; - return ImplicitConvert(cx, vp, baseType, data, false, NULL); + return ImplicitConvert(cx, vp, baseType, data, false, nullptr); } bool ArrayType::AddressOfElement(JSContext* cx, unsigned argc, jsval* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedObject obj(cx, JS_THIS_OBJECT(cx, vp)); if (!obj) @@ -4561,17 +4561,17 @@ ArrayType::AddressOfElement(JSContext* c } RootedObject baseType(cx, GetBaseType(typeObj)); RootedObject pointerType(cx, PointerType::CreateInternal(cx, baseType)); if (!pointerType) return false; // Create a PointerType CData object containing null. - RootedObject result(cx, CData::Create(cx, pointerType, NullPtr(), NULL, true)); + RootedObject result(cx, CData::Create(cx, pointerType, NullPtr(), nullptr, true)); if (!result) return false; args.rval().setObject(*result); // Convert the index to a size_t and bounds-check it. size_t index; size_t length = GetLength(typeObj); @@ -4594,87 +4594,87 @@ ArrayType::AddressOfElement(JSContext* c // For a struct field descriptor 'val' of the form { name : type }, extract // 'name' and 'type'. static JSFlatString* ExtractStructField(JSContext* cx, jsval val, JSObject** typeObj) { if (JSVAL_IS_PRIMITIVE(val)) { JS_ReportError(cx, "struct field descriptors require a valid name and type"); - return NULL; + return nullptr; } RootedObject obj(cx, JSVAL_TO_OBJECT(val)); RootedObject iter(cx, JS_NewPropertyIterator(cx, obj)); if (!iter) - return NULL; + return nullptr; RootedId nameid(cx); if (!JS_NextProperty(cx, iter, nameid.address())) - return NULL; + return nullptr; if (JSID_IS_VOID(nameid)) { JS_ReportError(cx, "struct field descriptors require a valid name and type"); - return NULL; + return nullptr; } if (!JSID_IS_STRING(nameid)) { JS_ReportError(cx, "struct field descriptors require a valid name and type"); - return NULL; + return nullptr; } // make sure we have one, and only one, property jsid id; if (!JS_NextProperty(cx, iter, &id)) - return NULL; + return nullptr; if (!JSID_IS_VOID(id)) { JS_ReportError(cx, "struct field descriptors must contain one property"); - return NULL; + return nullptr; } RootedValue propVal(cx); if (!JS_GetPropertyById(cx, obj, nameid, &propVal)) - return NULL; + return nullptr; if (propVal.isPrimitive() || !CType::IsCType(&propVal.toObject())) { JS_ReportError(cx, "struct field descriptors require a valid name and type"); - return NULL; + return nullptr; } // Undefined size or zero size struct members are illegal. // (Zero-size arrays are legal as struct members in C++, but libffi will // choke on a zero-size struct, so we disallow them.) *typeObj = &propVal.toObject(); size_t size; if (!CType::GetSafeSize(*typeObj, &size) || size == 0) { JS_ReportError(cx, "struct field types must have defined and nonzero size"); - return NULL; + return nullptr; } return JSID_TO_FLAT_STRING(nameid); } // For a struct field with 'name' and 'type', add an element of the form // { name : type }. static bool AddFieldToArray(JSContext* cx, jsval* element, JSFlatString* name_, JSObject* typeObj_) { RootedObject typeObj(cx, typeObj_); Rooted<JSFlatString*> name(cx, name_); - RootedObject fieldObj(cx, JS_NewObject(cx, NULL, NULL, NULL)); + RootedObject fieldObj(cx, JS_NewObject(cx, nullptr, nullptr, nullptr)); if (!fieldObj) return false; *element = OBJECT_TO_JSVAL(fieldObj); if (!JS_DefineUCProperty(cx, fieldObj, name->chars(), name->length(), - OBJECT_TO_JSVAL(typeObj), NULL, NULL, + OBJECT_TO_JSVAL(typeObj), nullptr, nullptr, JSPROP_ENUMERATE | JSPROP_READONLY | JSPROP_PERMANENT)) return false; return JS_FreezeObject(cx, fieldObj); } bool StructType::Create(JSContext* cx, unsigned argc, jsval* vp) @@ -4695,22 +4695,22 @@ StructType::Create(JSContext* cx, unsign // Get ctypes.StructType.prototype from the ctypes.StructType constructor. RootedObject typeProto(cx, CType::GetProtoFromCtor(&args.callee(), SLOT_STRUCTPROTO)); // Create a simple StructType with no defined fields. The result will be // non-instantiable as CData, will have no 'prototype' property, and will // have undefined size and alignment and no ffi_type. RootedObject result(cx, CType::Create(cx, typeProto, NullPtr(), TYPE_struct, - JSVAL_TO_STRING(name), JSVAL_VOID, JSVAL_VOID, NULL)); + JSVAL_TO_STRING(name), JSVAL_VOID, JSVAL_VOID, nullptr)); if (!result) return false; if (args.length() == 2) { - RootedObject arr(cx, JSVAL_IS_PRIMITIVE(args[1]) ? NULL : &args[1].toObject()); + RootedObject arr(cx, JSVAL_IS_PRIMITIVE(args[1]) ? nullptr : &args[1].toObject()); if (!arr || !JS_IsArrayObject(cx, arr)) { JS_ReportError(cx, "second argument must be an array"); return false; } // Define the struct fields. if (!DefineInternal(cx, result, arr)) return false; @@ -4743,22 +4743,22 @@ StructType::DefineInternal(JSContext* cx // ctypes.CType.prototype. RootedObject dataProto(cx, CType::GetProtoFromType(cx, typeObj, SLOT_STRUCTDATAPROTO)); if (!dataProto) return false; // Set up the 'prototype' and 'prototype.constructor' properties. // The prototype will reflect the struct fields as properties on CData objects // created from this type. - RootedObject prototype(cx, JS_NewObject(cx, &sCDataProtoClass, dataProto, NULL)); + RootedObject prototype(cx, JS_NewObject(cx, &sCDataProtoClass, dataProto, nullptr)); if (!prototype) return false; if (!JS_DefineProperty(cx, prototype, "constructor", OBJECT_TO_JSVAL(typeObj), - NULL, NULL, JSPROP_READONLY | JSPROP_PERMANENT)) + nullptr, nullptr, JSPROP_READONLY | JSPROP_PERMANENT)) return false; // Create a FieldInfoHash to stash on the type object, and an array to root // its constituents. (We cannot simply stash the hash in a reserved slot now // to get GC safety for free, since if anything in this function fails we // do not want to mutate 'typeObj'.) AutoPtr<FieldInfoHash> fields(cx->new_<FieldInfoHash>()); Array<jsval, 16> fieldRootsArray; @@ -4775,17 +4775,17 @@ StructType::DefineInternal(JSContext* cx structSize = 0; structAlign = 0; for (uint32_t i = 0; i < len; ++i) { RootedValue item(cx); if (!JS_GetElement(cx, fieldsObj, i, &item)) return false; - RootedObject fieldType(cx, NULL); + RootedObject fieldType(cx, nullptr); JSFlatString* flat = ExtractStructField(cx, item, fieldType.address()); if (!flat) return false; Rooted<JSStableString*> name(cx, flat->ensureStable(cx)); if (!name) return false; fieldRootsArray[i] = OBJECT_TO_JSVAL(fieldType); @@ -4870,60 +4870,60 @@ StructType::BuildFFIType(JSContext* cx, size_t len = fields->count(); size_t structSize = CType::GetSize(obj); size_t structAlign = CType::GetAlignment(obj); AutoPtr<ffi_type> ffiType(cx->new_<ffi_type>()); if (!ffiType) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } ffiType->type = FFI_TYPE_STRUCT; AutoPtr<ffi_type*> elements; if (len != 0) { elements = cx->pod_malloc<ffi_type*>(len + 1); if (!elements) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } - elements[len] = NULL; + elements[len] = nullptr; for (FieldInfoHash::Range r = fields->all(); !r.empty(); r.popFront()) { const FieldInfoHash::Entry& entry = r.front(); ffi_type* fieldType = CType::GetFFIType(cx, entry.value.mType); if (!fieldType) - return NULL; + return nullptr; elements[entry.value.mIndex] = fieldType; } } else { // Represent an empty struct as having a size of 1 byte, just like C++. JS_ASSERT(structSize == 1); JS_ASSERT(structAlign == 1); elements = cx->pod_malloc<ffi_type*>(2); if (!elements) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } elements[0] = &ffi_type_uint8; - elements[1] = NULL; + elements[1] = nullptr; } ffiType->elements = elements.get(); #ifdef DEBUG // Perform a sanity check: the result of our struct size and alignment // calculations should match libffi's. We force it to do this calculation // by calling ffi_prep_cif. ffi_cif cif; ffiType->size = 0; ffiType->alignment = 0; - ffi_status status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, ffiType.get(), NULL); + ffi_status status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, ffiType.get(), nullptr); JS_ASSERT(status == FFI_OK); JS_ASSERT(structSize == ffiType->size); JS_ASSERT(structAlign == ffiType->alignment); #else // Fill in the ffi_type's size and align fields. This makes libffi treat the // type as initialized; it will not recompute the values. (We assume // everything agrees; if it doesn't, we really want to know about it, which // is the purpose of the above debug-only check.) @@ -4982,17 +4982,17 @@ StructType::ConstructData(JSContext* cx, return false; } if (!CType::IsSizeDefined(obj)) { JS_ReportError(cx, "cannot construct an opaque StructType"); return false; } - JSObject* result = CData::Create(cx, obj, NullPtr(), NULL, true); + JSObject* result = CData::Create(cx, obj, NullPtr(), nullptr, true); if (!result) return false; args.rval().setObject(*result); if (args.length() == 0) return true; @@ -5030,17 +5030,17 @@ StructType::ConstructData(JSContext* cx, // We have a type constructor of the form 'ctypes.StructType(a, b, c, ...)'. // ImplicitConvert each field. if (args.length() == fields->count()) { for (FieldInfoHash::Range r = fields->all(); !r.empty(); r.popFront()) { const FieldInfo& field = r.front().value; STATIC_ASSUME(field.mIndex < fields->count()); /* Quantified invariant */ if (!ImplicitConvert(cx, args[field.mIndex], field.mType, buffer + field.mOffset, - false, NULL)) + false, nullptr)) return false; } return true; } JS_ReportError(cx, "constructor takes 0, 1, or %u arguments", fields->count()); @@ -5066,53 +5066,53 @@ StructType::LookupField(JSContext* cx, J JS_ASSERT(CType::GetTypeCode(obj) == TYPE_struct); FieldInfoHash::Ptr ptr = GetFieldInfo(obj)->lookup(name); if (ptr) return &ptr->value; JSAutoByteString bytes(cx, name); if (!bytes) - return NULL; + return nullptr; JS_ReportError(cx, "%s does not name a field", bytes.ptr()); - return NULL; + return nullptr; } JSObject* StructType::BuildFieldsArray(JSContext* cx, JSObject* obj) { JS_ASSERT(CType::IsCType(obj)); JS_ASSERT(CType::GetTypeCode(obj) == TYPE_struct); JS_ASSERT(CType::IsSizeDefined(obj)); const FieldInfoHash* fields = GetFieldInfo(obj); size_t len = fields->count(); // Prepare a new array for the 'fields' property of the StructType. Array<jsval, 16> fieldsVec; if (!fieldsVec.appendN(JSVAL_VOID, len)) - return NULL; + return nullptr; js::AutoArrayRooter root(cx, fieldsVec.length(), fieldsVec.begin()); for (FieldInfoHash::Range r = fields->all(); !r.empty(); r.popFront()) { const FieldInfoHash::Entry& entry = r.front(); // Add the field descriptor to the array. if (!AddFieldToArray(cx, &fieldsVec[entry.value.mIndex], entry.key, entry.value.mType)) - return NULL; + return nullptr; } RootedObject fieldsProp(cx, JS_NewArrayObject(cx, len, fieldsVec.begin())); if (!fieldsProp) - return NULL; + return nullptr; // Seal the fields array. if (!JS_FreezeObject(cx, fieldsProp)) - return NULL; + return nullptr; return fieldsProp; } bool StructType::FieldsArrayGetter(JSContext* cx, HandleObject obj, HandleId idval, MutableHandleValue vp) { if (!CType::IsCType(obj) || CType::GetTypeCode(obj) != TYPE_struct) { @@ -5179,17 +5179,17 @@ StructType::FieldSetter(JSContext* cx, H return false; } const FieldInfo* field = LookupField(cx, typeObj, JSID_TO_FLAT_STRING(idval)); if (!field) return false; char* data = static_cast<char*>(CData::GetData(obj)) + field->mOffset; - return ImplicitConvert(cx, vp, field->mType, data, false, NULL); + return ImplicitConvert(cx, vp, field->mType, data, false, nullptr); } bool StructType::AddressOfField(JSContext* cx, unsigned argc, jsval* vp) { CallArgs args = CallArgsFromVp(argc, vp); RootedObject obj(cx, JS_THIS_OBJECT(cx, vp)); if (!obj) @@ -5219,17 +5219,17 @@ StructType::AddressOfField(JSContext* cx return false; RootedObject baseType(cx, field->mType); RootedObject pointerType(cx, PointerType::CreateInternal(cx, baseType)); if (!pointerType) return false; // Create a PointerType CData object containing null. - JSObject* result = CData::Create(cx, pointerType, NullPtr(), NULL, true); + JSObject* result = CData::Create(cx, pointerType, NullPtr(), nullptr, true); if (!result) return false; args.rval().setObject(*result); // Manually set the pointer inside the object, so we skip the conversion step. void** data = static_cast<void**>(CData::GetData(result)); *data = static_cast<char*>(CData::GetData(obj)) + field->mOffset; @@ -5238,31 +5238,31 @@ StructType::AddressOfField(JSContext* cx /******************************************************************************* ** FunctionType implementation *******************************************************************************/ // Helper class for handling allocation of function arguments. struct AutoValue { - AutoValue() : mData(NULL) { } + AutoValue() : mData(nullptr) { } ~AutoValue() { js_free(mData); } bool SizeToType(JSContext* cx, JSObject* type) { // Allocate a minimum of sizeof(ffi_arg) to handle small integers. size_t size = Align(CType::GetSize(type), sizeof(ffi_arg)); mData = js_malloc(size); if (mData) memset(mData, 0, size); - return mData != NULL; + return mData != nullptr; } void* mData; }; static bool GetABI(JSContext* cx, jsval abiType, ffi_abi* result) { @@ -5296,68 +5296,68 @@ GetABI(JSContext* cx, jsval abiType, ffi } static JSObject* PrepareType(JSContext* cx, jsval type) { if (JSVAL_IS_PRIMITIVE(type) || !CType::IsCType(JSVAL_TO_OBJECT(type))) { JS_ReportError(cx, "not a ctypes type"); - return NULL; + return nullptr; } JSObject* result = JSVAL_TO_OBJECT(type); TypeCode typeCode = CType::GetTypeCode(result); if (typeCode == TYPE_array) { // convert array argument types to pointers, just like C. // ImplicitConvert will do the same, when passing an array as data. RootedObject baseType(cx, ArrayType::GetBaseType(result)); result = PointerType::CreateInternal(cx, baseType); if (!result) - return NULL; + return nullptr; } else if (typeCode == TYPE_void_t || typeCode == TYPE_function) { // disallow void or function argument types JS_ReportError(cx, "Cannot have void or function argument type"); - return NULL; + return nullptr; } if (!CType::IsSizeDefined(result)) { JS_ReportError(cx, "Argument type must have defined size"); - return NULL; + return nullptr; } // libffi cannot pass types of zero size by value. JS_ASSERT(CType::GetSize(result) != 0); return result; } static JSObject* PrepareReturnType(JSContext* cx, jsval type) { if (JSVAL_IS_PRIMITIVE(type) || !CType::IsCType(JSVAL_TO_OBJECT(type))) { JS_ReportError(cx, "not a ctypes type"); - return NULL; + return nullptr; } JSObject* result = JSVAL_TO_OBJECT(type); TypeCode typeCode = CType::GetTypeCode(result); // Arrays and functions can never be return types. if (typeCode == TYPE_array || typeCode == TYPE_function) { JS_ReportError(cx, "Return type cannot be an array or function"); - return NULL; + return nullptr; } if (typeCode != TYPE_void_t && !CType::IsSizeDefined(result)) { JS_ReportError(cx, "Return type must have defined size"); - return NULL; + return nullptr; } // libffi cannot pass types of zero size by value. JS_ASSERT(typeCode == TYPE_void_t || CType::GetSize(result) != 0); return result; } @@ -5466,98 +5466,98 @@ NewFunctionInfo(JSContext* cx, jsval abiType, jsval returnType, jsval* argTypes, unsigned argLength) { AutoPtr<FunctionInfo> fninfo(cx->new_<FunctionInfo>()); if (!fninfo) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } ffi_abi abi; if (!GetABI(cx, abiType, &abi)) { JS_ReportError(cx, "Invalid ABI specification"); - return NULL; + return nullptr; } fninfo->mABI = JSVAL_TO_OBJECT(abiType); // prepare the result type fninfo->mReturnType = PrepareReturnType(cx, returnType); if (!fninfo->mReturnType) - return NULL; + return nullptr; // prepare the argument types if (!fninfo->mArgTypes.reserve(argLength) || !fninfo->mFFITypes.reserve(argLength)) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } fninfo->mIsVariadic = false; for (uint32_t i = 0; i < argLength; ++i) { bool isEllipsis; if (!IsEllipsis(cx, argTypes[i], &isEllipsis)) - return NULL; + return nullptr; if (isEllipsis) { fninfo->mIsVariadic = true; if (i < 1) { JS_ReportError(cx, "\"...\" may not be the first and only parameter " "type of a variadic function declaration"); - return NULL; + return nullptr; } if (i < argLength - 1) { JS_ReportError(cx, "\"...\" must be the last parameter type of a " "variadic function declaration"); - return NULL; + return nullptr; } if (GetABICode(fninfo->mABI) != ABI_DEFAULT) { JS_ReportError(cx, "Variadic functions must use the __cdecl calling " "convention"); - return NULL; + return nullptr; } break; } JSObject* argType = PrepareType(cx, argTypes[i]); if (!argType) - return NULL; + return nullptr; ffi_type* ffiType = CType::GetFFIType(cx, argType); if (!ffiType) - return NULL; + return nullptr; fninfo->mArgTypes.infallibleAppend(argType); fninfo->mFFITypes.infallibleAppend(ffiType); } if (fninfo->mIsVariadic) // wait to PrepareCIF until function is called return fninfo.forget(); if (!PrepareCIF(cx, fninfo.get())) - return NULL; + return nullptr; return fninfo.forget(); } bool FunctionType::Create(JSContext* cx, unsigned argc, jsval* vp) { // Construct and return a new FunctionType object. CallArgs args = CallArgsFromVp(argc, vp); if (args.length() < 2 || args.length() > 3) { JS_ReportError(cx, "FunctionType takes two or three arguments"); return false; } AutoValueVector argTypes(cx); - RootedObject arrayObj(cx, NULL); + RootedObject arrayObj(cx, nullptr); if (args.length() == 3) { // Prepare an array of jsvals for the arguments. if (!JSVAL_IS_PRIMITIVE(args[2])) arrayObj = &args[2].toObject(); if (!arrayObj || !JS_IsArrayObject(cx, arrayObj)) { JS_ReportError(cx, "third argument must be an array"); return false; @@ -5593,34 +5593,34 @@ FunctionType::CreateInternal(JSContext* jsval abi, jsval rtype, jsval* argtypes, unsigned arglen) { // Determine and check the types, and prepare the function CIF. AutoPtr<FunctionInfo> fninfo(NewFunctionInfo(cx, abi, rtype, argtypes, arglen)); if (!fninfo) - return NULL; + return nullptr; // Get ctypes.FunctionType.prototype and the common prototype for CData objects // of this type, from ctypes.CType.prototype. RootedObject typeProto(cx, CType::GetProtoFromType(cx, fninfo->mReturnType, SLOT_FUNCTIONPROTO)); if (!typeProto) - return NULL; + return nullptr; RootedObject dataProto(cx, CType::GetProtoFromType(cx, fninfo->mReturnType, SLOT_FUNCTIONDATAPROTO)); if (!dataProto) - return NULL; + return nullptr; // Create a new CType object with the common properties and slots. JSObject* typeObj = CType::Create(cx, typeProto, dataProto, TYPE_function, - NULL, JSVAL_VOID, JSVAL_VOID, NULL); + nullptr, JSVAL_VOID, JSVAL_VOID, nullptr); if (!typeObj) - return NULL; + return nullptr; // Stash the FunctionInfo in a reserved slot. JS_SetReservedSlot(typeObj, SLOT_FNINFO, PRIVATE_TO_JSVAL(fninfo.forget())); return typeObj; } // Construct a function pointer to a JS function (see CClosure::Create()). @@ -5959,92 +5959,92 @@ CClosure::Create(JSContext* cx, HandleObject fnObj, HandleObject thisObj, jsval errVal_, PRFuncPtr* fnptr) { RootedValue errVal(cx, errVal_); JS_ASSERT(fnObj); - RootedObject result(cx, JS_NewObject(cx, &sCClosureClass, NULL, NULL)); + RootedObject result(cx, JS_NewObject(cx, &sCClosureClass, nullptr, nullptr)); if (!result) - return NULL; + return nullptr; // Get the FunctionInfo from the FunctionType. FunctionInfo* fninfo = FunctionType::GetFunctionInfo(typeObj); JS_ASSERT(!fninfo->mIsVariadic); JS_ASSERT(GetABICode(fninfo->mABI) != ABI_WINAPI); AutoPtr<ClosureInfo> cinfo(cx->new_<ClosureInfo>(JS_GetRuntime(cx))); if (!cinfo) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } // Get the prototype of the FunctionType object, of class CTypeProto, // which stores our JSContext for use with the closure. RootedObject proto(cx); if (!JS_GetPrototype(cx, typeObj, &proto)) - return NULL; + return nullptr; JS_ASSERT(proto); JS_ASSERT(CType::IsCTypeProto(proto)); // Get a JSContext for use with the closure. cinfo->cx = js::DefaultJSContext(JS_GetRuntime(cx)); // Prepare the error sentinel value. It's important to do this now, because // we might be unable to convert the value to the proper type. If so, we want // the caller to know about it _now_, rather than some uncertain time in the // future when the error sentinel is actually needed. if (!JSVAL_IS_VOID(errVal)) { // Make sure the callback returns something. if (CType::GetTypeCode(fninfo->mReturnType) == TYPE_void_t) { JS_ReportError(cx, "A void callback can't pass an error sentinel"); - return NULL; + return nullptr; } // With the exception of void, the FunctionType constructor ensures that // the return type has a defined size. JS_ASSERT(CType::IsSizeDefined(fninfo->mReturnType)); // Allocate a buffer for the return value. size_t rvSize = CType::GetSize(fninfo->mReturnType); cinfo->errResult = cx->malloc_(rvSize); if (!cinfo->errResult) - return NULL; + return nullptr; // Do the value conversion. This might fail, in which case we throw. if (!ImplicitConvert(cx, errVal, fninfo->mReturnType, cinfo->errResult, - false, NULL)) - return NULL; + false, nullptr)) + return nullptr; } else { - cinfo->errResult = NULL; + cinfo->errResult = nullptr; } // Copy the important bits of context into cinfo. cinfo->closureObj = result; cinfo->typeObj = typeObj; cinfo->thisObj = thisObj; cinfo->jsfnObj = fnObj; // Create an ffi_closure object and initialize it. void* code; cinfo->closure = static_cast<ffi_closure*>(ffi_closure_alloc(sizeof(ffi_closure), &code)); if (!cinfo->closure || !code) { JS_ReportError(cx, "couldn't create closure - libffi error"); - return NULL; + return nullptr; } ffi_status status = ffi_prep_closure_loc(cinfo->closure, &fninfo->mCIF, CClosure::ClosureStub, cinfo.get(), code); if (status != FFI_OK) { JS_ReportError(cx, "couldn't create closure - libffi error"); - return NULL; + return nullptr; } // Stash the ClosureInfo struct on our new object. JS_SetReservedSlot(result, SLOT_CLOSUREINFO, PRIVATE_TO_JSVAL(cinfo.forget())); // Casting between void* and a function pointer is forbidden in C and C++. // Do it via an integral type. *fnptr = reinterpret_cast<PRFuncPtr>(reinterpret_cast<uintptr_t>(code)); @@ -6146,30 +6146,30 @@ CClosure::ClosureStub(ffi_cif* cif, void for (uint32_t i = 0; i < cif->nargs; ++i) { // Convert each argument, and have any CData objects created depend on // the existing buffers. RootedObject argType(cx, fninfo->mArgTypes[i]); if (!ConvertToJS(cx, argType, NullPtr(), args[i], false, false, &argv[i])) return; } - // Call the JS function. 'thisObj' may be NULL, in which case the JS engine - // will find an appropriate object to use. + // Call the JS function. 'thisObj' may be nullptr, in which case the JS + // engine will find an appropriate object to use. RootedValue rval(cx); bool success = JS_CallFunctionValue(cx, thisObj, OBJECT_TO_JSVAL(jsfnObj), cif->nargs, argv.begin(), rval.address()); // Convert the result. Note that we pass 'isArgument = false', such that // ImplicitConvert will *not* autoconvert a JS string into a pointer-to-char // type, which would require an allocation that we can't track. The JS // function must perform this conversion itself and return a PointerType // CData; thusly, the burden of freeing the data is left to the user. if (success && cif->rtype != &ffi_type_void) success = ImplicitConvert(cx, rval, fninfo->mReturnType, result, false, - NULL); + nullptr); if (!success) { // Something failed. The callee may have thrown, or it may not have // returned a value that ImplicitConvert() was happy with. Depending on how // prudent the consumer has been, we may or may not have a recovery plan. // In any case, a JS exception cannot be passed to C code, so report the // exception if any and clear it from the cx. @@ -6231,17 +6231,18 @@ CClosure::ClosureStub(ffi_cif* cif, void // // * If an object 'refObj' is supplied, the new CData object stores the // referent object in a reserved slot for GC safety, such that 'refObj' will // be held alive by the resulting CData object. 'refObj' may or may not be // a CData object; merely an object we want to keep alive. // * If 'refObj' is a CData object, 'ownResult' must be false. // * Otherwise, 'refObj' is a Library or CClosure object, and 'ownResult' // may be true or false. -// * Otherwise 'refObj' is NULL. In this case, 'ownResult' may be true or false. +// * Otherwise 'refObj' is nullptr. In this case, 'ownResult' may be true or +// false. // // * If 'ownResult' is true, the CData object will allocate an appropriately // sized buffer, and free it upon finalization. If 'source' data is // supplied, the data will be copied from 'source' into the buffer; // otherwise, the entirety of the new buffer will be initialized to zero. // * If 'ownResult' is false, the new CData's buffer refers to a slice of // another buffer kept alive by 'refObj'. 'source' data must be provided, // and the new CData's buffer will refer to 'source'. @@ -6263,48 +6264,48 @@ CData::Create(JSContext* cx, JS_ASSERT(!JSVAL_IS_PRIMITIVE(slot)); RootedObject proto(cx, JSVAL_TO_OBJECT(slot)); RootedObject parent(cx, JS_GetParent(typeObj)); JS_ASSERT(parent); RootedObject dataObj(cx, JS_NewObject(cx, &sCDataClass, proto, parent)); if (!dataObj) - return NULL; + return nullptr; // set the CData's associated type JS_SetReservedSlot(dataObj, SLOT_CTYPE, OBJECT_TO_JSVAL(typeObj)); // Stash the referent object, if any, for GC safety. if (refObj) JS_SetReservedSlot(dataObj, SLOT_REFERENT, OBJECT_TO_JSVAL(refObj)); // Set our ownership flag. JS_SetReservedSlot(dataObj, SLOT_OWNS, BOOLEAN_TO_JSVAL(ownResult)); // attach the buffer. since it might not be 2-byte aligned, we need to // allocate an aligned space for it and store it there. :( char** buffer = cx->new_<char*>(); if (!buffer) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } char* data; if (!ownResult) { data = static_cast<char*>(source); } else { // Initialize our own buffer. size_t size = CType::GetSize(typeObj); data = (char*)cx->malloc_(size); if (!data) { // Report a catchable allocation error. JS_ReportAllocationOverflow(cx); js_free(buffer); - return NULL; + return nullptr; } if (!source) memset(data, 0, size); else memcpy(data, source, size); } @@ -6389,17 +6390,17 @@ CData::ValueGetter(JSContext* cx, Handle bool CData::ValueSetter(JSContext* cx, HandleObject obj, HandleId idval, bool strict, MutableHandleValue vp) { if (!IsCData(obj)) { JS_ReportError(cx, "not a CData"); return false; } - return ImplicitConvert(cx, vp, GetCType(obj), GetData(obj), false, NULL); + return ImplicitConvert(cx, vp, GetCType(obj), GetData(obj), false, nullptr); } bool CData::Address(JSContext* cx, unsigned argc, jsval* vp) { CallArgs args = CallArgsFromVp(argc, vp); if (args.length() != 0) { JS_ReportError(cx, "address takes zero arguments"); @@ -6415,17 +6416,17 @@ CData::Address(JSContext* cx, unsigned a } RootedObject typeObj(cx, CData::GetCType(obj)); RootedObject pointerType(cx, PointerType::CreateInternal(cx, typeObj)); if (!pointerType) return false; // Create a PointerType CData object containing null. - JSObject* result = CData::Create(cx, pointerType, NullPtr(), NULL, true); + JSObject* result = CData::Create(cx, pointerType, NullPtr(), nullptr, true); if (!result) return false; args.rval().setObject(*result); // Manually set the pointer inside the object, so we skip the conversion step. void** data = static_cast<void**>(GetData(result)); *data = GetData(obj); @@ -6530,17 +6531,17 @@ ReadStringCommon(JSContext* cx, InflateU JSObject* typeObj = CData::GetCType(obj); TypeCode typeCode = CType::GetTypeCode(typeObj); void* data; size_t maxLength = -1; switch (typeCode) { case TYPE_pointer: baseType = PointerType::GetBaseType(typeObj); data = *static_cast<void**>(CData::GetData(obj)); - if (data == NULL) { + if (data == nullptr) { JS_ReportError(cx, "cannot read contents of null pointer"); return false; } break; case TYPE_array: baseType = ArrayType::GetBaseType(typeObj); data = CData::GetData(obj); maxLength = ArrayType::GetLength(typeObj); @@ -6613,17 +6614,17 @@ CData::GetSourceString(JSContext *cx, Ha // 't.ptr' for pointers; // 't.array([n])' for arrays; // 'n' for structs, where n = t.name, the struct's name. (We assume this is // bound to a variable in the current scope.) AutoString source; BuildTypeSource(cx, typeObj, true, source); AppendString(source, "("); if (!BuildDataSource(cx, typeObj, data, false, source)) - return NULL; + return nullptr; AppendString(source, ")"); return NewUCString(cx, source); } bool CData::ToSource(JSContext* cx, unsigned argc, jsval* vp) @@ -6787,40 +6788,40 @@ CDataFinalizer::IsCDataFinalizer(JSObjec JSObject * CDataFinalizer::GetCType(JSContext *cx, JSObject *obj) { MOZ_ASSERT(IsCDataFinalizer(obj)); jsval valData = JS_GetReservedSlot(obj, SLOT_DATAFINALIZER_VALTYPE); if (JSVAL_IS_VOID(valData)) { - return NULL; + return nullptr; } return JSVAL_TO_OBJECT(valData); } JSObject* CDataFinalizer::GetCData(JSContext *cx, JSObject *obj) { if (!obj) { JS_ReportError(cx, "No C data"); - return NULL; + return nullptr; } if (CData::IsCData(obj)) { return obj; } if (!CDataFinalizer::IsCDataFinalizer(obj)) { JS_ReportError(cx, "Not C data"); - return NULL; + return nullptr; } RootedValue val(cx); if (!CDataFinalizer::GetValue(cx, obj, val.address()) || JSVAL_IS_PRIMITIVE(val)) { JS_ReportError(cx, "Empty CDataFinalizer"); - return NULL; + return nullptr; } return JSVAL_TO_OBJECT(val); } bool CDataFinalizer::GetValue(JSContext *cx, JSObject *obj, jsval *aResult) { MOZ_ASSERT(IsCDataFinalizer(obj)); @@ -6858,17 +6859,17 @@ CDataFinalizer::Construct(JSContext* cx, RootedObject objProto(cx); if (!GetObjectProperty(cx, objSelf, "prototype", &objProto)) { JS_ReportError(cx, "CDataFinalizer.prototype does not exist"); return false; } // Get arguments if (args.length() == 0) { // Special case: the empty (already finalized) object - JSObject *objResult = JS_NewObject(cx, &sCDataFinalizerClass, objProto, NULL); + JSObject *objResult = JS_NewObject(cx, &sCDataFinalizerClass, objProto, nullptr); args.rval().setObject(*objResult); return true; } if (args.length() != 2) { JS_ReportError(cx, "CDataFinalizer takes 2 arguments"); return false; } @@ -6954,17 +6955,17 @@ CDataFinalizer::Construct(JSContext* cx, ScopedJSFreePtr<void> rvalue; if (CType::GetTypeCode(returnType) != TYPE_void_t) { rvalue = malloc(Align(CType::GetSize(returnType), sizeof(ffi_arg))); } //Otherwise, simply do not allocate // 5. Create |objResult| - JSObject *objResult = JS_NewObject(cx, &sCDataFinalizerClass, objProto, NULL); + JSObject *objResult = JS_NewObject(cx, &sCDataFinalizerClass, objProto, nullptr); if (!objResult) { return false; } // If our argument is a CData, it holds a type. // This is the type that we should capture, not that // of the function, which may be less precise. JSObject *objBestArgType = objArgType; @@ -7028,20 +7029,20 @@ CDataFinalizer::Construct(JSContext* cx, * Actually call the finalizer. Does not perform any cleanup on the object. * * Preconditions: |this| must be a |CDataFinalizer|, |p| must be non-null. * The function fails if |this| has gone through |Forget|/|Dispose| * or |Finalize|. * * This function does not alter the value of |errno|/|GetLastError|. * - * If argument |errnoStatus| is non-NULL, it receives the value of |errno| + * If argument |errnoStatus| is non-nullptr, it receives the value of |errno| * immediately after the call. Under Windows, if argument |lastErrorStatus| - * is non-NULL, it receives the value of |GetLastError| immediately after the - * call. On other platforms, |lastErrorStatus| is ignored. + * is non-nullptr, it receives the value of |GetLastError| immediately after + * the call. On other platforms, |lastErrorStatus| is ignored. */ void CDataFinalizer::CallFinalizer(CDataFinalizer::Private *p, int* errnoStatus, int32_t* lastErrorStatus) { int savedErrno = errno; errno = 0; @@ -7163,17 +7164,17 @@ CDataFinalizer::Methods::Dispose(JSConte RootedObject resultType(cx, FunctionType::GetFunctionInfo(objCodeType)->mReturnType); RootedValue result(cx, JSVAL_VOID); int errnoStatus; #if defined(XP_WIN) int32_t lastErrorStatus; CDataFinalizer::CallFinalizer(p, &errnoStatus, &lastErrorStatus); #else - CDataFinalizer::CallFinalizer(p, &errnoStatus, NULL); + CDataFinalizer::CallFinalizer(p, &errnoStatus, nullptr); #endif // defined(XP_WIN) JS_SetReservedSlot(objCTypes, SLOT_ERRNO, INT_TO_JSVAL(errnoStatus)); #if defined(XP_WIN) JS_SetReservedSlot(objCTypes, SLOT_LASTERROR, INT_TO_JSVAL(lastErrorStatus)); #endif // defined(XP_WIN) if (ConvertToJS(cx, resultType, NullPtr(), p->rvalue, false, true, result.address())) { @@ -7200,30 +7201,30 @@ CDataFinalizer::Finalize(JSFreeOp* fop, { CDataFinalizer::Private *p = (CDataFinalizer::Private *) JS_GetPrivate(obj); if (!p) { return; } - CDataFinalizer::CallFinalizer(p, NULL, NULL); - CDataFinalizer::Cleanup(p, NULL); + CDataFinalizer::CallFinalizer(p, nullptr, nullptr); + CDataFinalizer::Cleanup(p, nullptr); } /* * Perform cleanup of a CDataFinalizer * * Release strong references, cleanup |Private|. * - * Argument |p| contains the private information of the CDataFinalizer. If NULL, - * this function does nothing. - * Argument |obj| should contain |NULL| during finalization (or in any context - * in which the object itself should not be cleaned up), or a CDataFinalizer - * object otherwise. + * Argument |p| contains the private information of the CDataFinalizer. If + * nullptr, this function does nothing. + * Argument |obj| should contain |nullptr| during finalization (or in any + * context in which the object itself should not be cleaned up), or a + * CDataFinalizer object otherwise. */ void CDataFinalizer::Cleanup(CDataFinalizer::Private *p, JSObject *obj) { if (!p) { return; // We have already cleaned up } @@ -7232,17 +7233,17 @@ CDataFinalizer::Cleanup(CDataFinalizer:: free(p); if (!obj) { return; // No slots to clean up } JS_ASSERT(CDataFinalizer::IsCDataFinalizer(obj)); - JS_SetPrivate(obj, NULL); + JS_SetPrivate(obj, nullptr); for (int i = 0; i < CDATAFINALIZER_SLOTS; ++i) { JS_SetReservedSlot(obj, i, JSVAL_NULL); } } /******************************************************************************* ** Int64 and UInt64 implementation @@ -7253,29 +7254,29 @@ Int64Base::Construct(JSContext* cx, HandleObject proto, uint64_t data, bool isUnsigned) { const JSClass* clasp = isUnsigned ? &sUInt64Class : &sInt64Class; RootedObject parent(cx, JS_GetParent(proto)); RootedObject result(cx, JS_NewObject(cx, clasp, proto, parent)); if (!result) - return NULL; + return nullptr; // attach the Int64's data uint64_t* buffer = cx->new_<uint64_t>(data); if (!buffer) { JS_ReportOutOfMemory(cx); - return NULL; + return nullptr; } JS_SetReservedSlot(result, SLOT_INT64, PRIVATE_TO_JSVAL(buffer)); if (!JS_FreezeObject(cx, result)) - return NULL; + return nullptr; return result; } void Int64Base::Finalize(JSFreeOp *fop, JSObject* obj) { jsval slot = JS_GetReservedSlot(obj, SLOT_INT64);
--- a/js/src/ctypes/CTypes.h +++ b/js/src/ctypes/CTypes.h @@ -22,30 +22,30 @@ namespace ctypes { // Class that takes ownership of a pointer T*, and calls cx->delete_() or // cx->array_delete() upon destruction. template<class T> class AutoPtr { private: typedef AutoPtr<T> self_type; public: - AutoPtr() : mPtr(NULL) { } + AutoPtr() : mPtr(nullptr) { } explicit AutoPtr(T* ptr) : mPtr(ptr) { } ~AutoPtr() { js_delete(mPtr); } T* operator->() { return mPtr; } - bool operator!() { return mPtr == NULL; } + bool operator!() { return mPtr == nullptr; } T& operator[](size_t i) { return *(mPtr + i); } // Note: we cannot safely provide an 'operator T*()', since this would allow // the compiler to perform implicit conversion from one AutoPtr to another // via the constructor AutoPtr(T*). T* get() { return mPtr; } - void set(T* other) { JS_ASSERT(mPtr == NULL); mPtr = other; } - T* forget() { T* result = mPtr; mPtr = NULL; return result; } + void set(T* other) { JS_ASSERT(mPtr == nullptr); mPtr = other; } + T* forget() { T* result = mPtr; mPtr = nullptr; return result; } self_type& operator=(T* rhs) { mPtr = rhs; return *this; } private: // Do not allow copy construction or assignment from another AutoPtr. AutoPtr(AutoPtr<T>&); self_type& operator=(AutoPtr<T>& rhs); @@ -86,33 +86,33 @@ AppendString(Vector<T, N, AP> &v, Vector v.append(w.begin(), w.length()); } template <size_t N, class AP> void AppendString(Vector<jschar, N, AP> &v, JSString* str) { JS_ASSERT(str); - const jschar *chars = str->getChars(NULL); + const jschar *chars = str->getChars(nullptr); if (!chars) return; v.append(chars, str->length()); } template <size_t N, class AP> void AppendString(Vector<char, N, AP> &v, JSString* str) { JS_ASSERT(str); size_t vlen = v.length(); size_t alen = str->length(); if (!v.resize(vlen + alen)) return; - const jschar *chars = str->getChars(NULL); + const jschar *chars = str->getChars(nullptr); if (!chars) return; for (size_t i = 0; i < alen; ++i) v[i + vlen] = char(chars[i]); } template <class T, size_t N, class AP, size_t ArrayLength> @@ -138,17 +138,17 @@ void PrependString(Vector<jschar, N, AP> &v, JSString* str) { JS_ASSERT(str); size_t vlen = v.length(); size_t alen = str->length(); if (!v.resize(vlen + alen)) return; - const jschar *chars = str->getChars(NULL); + const jschar *chars = str->getChars(nullptr); if (!chars) return; // Move vector data forward. This is safe since we've already resized. memmove(v.begin() + alen, v.begin(), vlen * sizeof(jschar)); // Copy data to insert. memcpy(v.begin(), chars, alen * sizeof(jschar)); @@ -282,21 +282,21 @@ struct ClosureInfo JS::Heap<JSObject*> closureObj; // CClosure object JS::Heap<JSObject*> typeObj; // FunctionType describing the C function JS::Heap<JSObject*> thisObj; // 'this' object to use for the JS function call JS::Heap<JSObject*> jsfnObj; // JS function void* errResult; // Result that will be returned if the closure throws ffi_closure* closure; // The C closure itself // Anything conditionally freed in the destructor should be initialized to - // NULL here. + // nullptr here. ClosureInfo(JSRuntime* runtime) : rt(runtime) - , errResult(NULL) - , closure(NULL) + , errResult(nullptr) + , closure(nullptr) {} ~ClosureInfo() { if (closure) ffi_closure_free(closure); js_free(errResult); } };
--- a/js/src/ctypes/Library.cpp +++ b/js/src/ctypes/Library.cpp @@ -53,17 +53,17 @@ bool Library::Name(JSContext* cx, unsigned argc, jsval *vp) { if (argc != 1) { JS_ReportError(cx, "libraryName takes one argument"); return false; } jsval arg = JS_ARGV(cx, vp)[0]; - JSString* str = NULL; + JSString* str = nullptr; if (JSVAL_IS_STRING(arg)) { str = JSVAL_TO_STRING(arg); } else { JS_ReportError(cx, "name argument must be a string"); return false; } @@ -80,66 +80,67 @@ Library::Name(JSContext* cx, unsigned ar JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(result)); return true; } JSObject* Library::Create(JSContext* cx, jsval path_, JSCTypesCallbacks* callbacks) { RootedValue path(cx, path_); - RootedObject libraryObj(cx, JS_NewObject(cx, &sLibraryClass, NULL, NULL)); + RootedObject libraryObj(cx, + JS_NewObject(cx, &sLibraryClass, nullptr, nullptr)); if (!libraryObj) - return NULL; + return nullptr; // initialize the library - JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL)); + JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(nullptr)); // attach API functions if (!JS_DefineFunctions(cx, libraryObj, sLibraryFunctions)) - return NULL; + return nullptr; if (!JSVAL_IS_STRING(path)) { JS_ReportError(cx, "open takes a string argument"); - return NULL; + return nullptr; } PRLibSpec libSpec; RootedFlatString pathStr(cx, JS_FlattenString(cx, JSVAL_TO_STRING(path))); if (!pathStr) - return NULL; + return nullptr; #ifdef XP_WIN // On Windows, converting to native charset may corrupt path string. // So, we have to use Unicode path directly. const PRUnichar* pathChars = JS_GetFlatStringChars(pathStr); if (!pathChars) - return NULL; + return nullptr; libSpec.value.pathname_u = pathChars; libSpec.type = PR_LibSpec_PathnameU; #else // Convert to platform native charset if the appropriate callback has been // provided. char* pathBytes; if (callbacks && callbacks->unicodeToNative) { pathBytes = callbacks->unicodeToNative(cx, pathStr->chars(), pathStr->length()); if (!pathBytes) - return NULL; + return nullptr; } else { // Fallback: assume the platform native charset is UTF-8. This is true // for Mac OS X, Android, and probably Linux. size_t nbytes = GetDeflatedUTF8StringLength(cx, pathStr->chars(), pathStr->length()); if (nbytes == (size_t) -1) - return NULL; + return nullptr; pathBytes = static_cast<char*>(JS_malloc(cx, nbytes + 1)); if (!pathBytes) - return NULL; + return nullptr; ASSERT_OK(DeflateStringToUTF8Buffer(cx, pathStr->chars(), pathStr->length(), pathBytes, &nbytes)); pathBytes[nbytes] = 0; } libSpec.value.pathname = pathBytes; libSpec.type = PR_LibSpec_Pathname; @@ -149,17 +150,17 @@ Library::Create(JSContext* cx, jsval pat if (!library) { #ifdef XP_WIN JS_ReportError(cx, "couldn't open library %hs", pathChars); #else JS_ReportError(cx, "couldn't open library %s", pathBytes); JS_free(cx, pathBytes); #endif - return NULL; + return nullptr; } #ifndef XP_WIN JS_free(cx, pathBytes); #endif // stash the library JS_SetReservedSlot(libraryObj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(library)); @@ -233,17 +234,17 @@ Library::Close(JSContext* cx, unsigned a if (argc != 0) { JS_ReportError(cx, "close doesn't take any arguments"); return false; } // delete our internal objects UnloadLibrary(obj); - JS_SetReservedSlot(obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(NULL)); + JS_SetReservedSlot(obj, SLOT_LIBRARY, PRIVATE_TO_JSVAL(nullptr)); JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; } bool Library::Declare(JSContext* cx, unsigned argc, jsval* vp) { @@ -277,17 +278,17 @@ Library::Declare(JSContext* cx, unsigned } jsval* argv = JS_ARGV(cx, vp); if (!JSVAL_IS_STRING(argv[0])) { JS_ReportError(cx, "first argument must be a string"); return false; } - RootedObject fnObj(cx, NULL); + RootedObject fnObj(cx, nullptr); RootedObject typeObj(cx); bool isFunction = argc > 2; if (isFunction) { // Case 1). // Create a FunctionType representing the function. fnObj = FunctionType::CreateInternal(cx, argv[1], argv[2], &argv[3], argc - 3); if (!fnObj)