#include "SelfHostingDefines.h"
#include "TypedObjectConstants.h"
#ifdef DEBUG
#define assert(b, info) \
do { \
if (!(b)) \
AssertionFailed(__FILE__ + ":" + __LINE__ + ": " + info) \
} while (false)
#define dbg(msg) \
do { \
DumpMessage(callFunction(std_Array_pop, \
StringSplitString(__FILE__, '/')) + \
'#' + __LINE__ + ': ' + msg) \
} while (false)
#else
#define assert(b, info) ; #define dbg(msg) ; #endif
var std_Symbol = Symbol;
function List() {
this.length = 0;
}
MakeConstructible(List, {__proto__: null});
function Record() {
return std_Object_create(null);
}
MakeConstructible(Record, {});
function ToBoolean(v) {
return !!v;
}
function ToNumber(v) {
return +v;
}
function RequireObjectCoercible(v) {
if (v === undefined || v === null)
ThrowTypeError(JSMSG_CANT_CONVERT_TO, ToString(v), "object");
}
function ToLength(v) {
v = ToInteger(v);
v = std_Math_max(v, 0);
return std_Math_min(v, 0x1fffffffffffff);
}
function SameValueZero(x, y) {
return x === y || (x !== x && y !== y);
}
function GetMethod(V, P) {
assert(IsPropertyKey(P), "Invalid property key");
var func = V[P];
if (func === undefined || func === null)
return undefined;
if (!IsCallable(func))
ThrowTypeError(JSMSG_NOT_FUNCTION, typeof func);
return func;
}
function IsPropertyKey(argument) {
var type = typeof argument;
return type === "string" || type === "symbol";
}
#define TO_PROPERTY_KEY(name) \
(typeof name !== "string" && typeof name !== "number" && typeof name !== "symbol" ? ToPropertyKey(name) : name)
var _builtinCtorsCache = {__proto__: null};
function GetBuiltinConstructor(builtinName) {
var ctor = _builtinCtorsCache[builtinName] ||
(_builtinCtorsCache[builtinName] = GetBuiltinConstructorImpl(builtinName));
assert(ctor, `No builtin with name "${builtinName}" found`);
return ctor;
}
function GetBuiltinPrototype(builtinName) {
return (_builtinCtorsCache[builtinName] || GetBuiltinConstructor(builtinName)).prototype;
}
function SpeciesConstructor(obj, defaultConstructor) {
assert(IsObject(obj), "not passed an object");
var ctor = obj.constructor;
if (ctor === undefined)
return defaultConstructor;
if (!IsObject(ctor))
ThrowTypeError(JSMSG_NOT_NONNULL_OBJECT, "object's 'constructor' property");
var s = ctor[std_species];
if (s === undefined || s === null)
return defaultConstructor;
if (IsConstructor(s))
return s;
ThrowTypeError(JSMSG_NOT_CONSTRUCTOR, "@@species property of object's constructor");
}
function GetTypeError(msg) {
try {
FUN_APPLY(ThrowTypeError, undefined, arguments);
} catch (e) {
return e;
}
assert(false, "the catch block should've returned from this function.");
}
function GetInternalError(msg) {
try {
FUN_APPLY(ThrowInternalError, undefined, arguments);
} catch (e) {
return e;
}
assert(false, "the catch block should've returned from this function.");
}
function NullFunction() {}
function CopyDataProperties(target, source, excludedItems) {
assert(IsObject(target), "target is an object");
assert(IsObject(excludedItems), "excludedItems is an object");
if (source === undefined || source === null)
return;
var from = ToObject(source);
var keys = CopyDataPropertiesOrGetOwnKeys(target, from, excludedItems);
if (keys === null)
return;
for (var index = 0; index < keys.length; index++) {
var key = keys[index];
if (!hasOwn(key, excludedItems) &&
callFunction(std_Object_propertyIsEnumerable, from, key))
{
_DefineDataProperty(target, key, from[key]);
}
}
}
function CopyDataPropertiesUnfiltered(target, source) {
assert(IsObject(target), "target is an object");
if (source === undefined || source === null)
return;
var from = ToObject(source);
var keys = CopyDataPropertiesOrGetOwnKeys(target, from, null);
if (keys === null)
return;
for (var index = 0; index < keys.length; index++) {
var key = keys[index];
if (callFunction(std_Object_propertyIsEnumerable, from, key))
_DefineDataProperty(target, key, from[key]);
}
}
function outer() {
return function inner() {
return "foo";
};
}