diff --git a/deps/chakrashim/lib/chakra_shim.js b/deps/chakrashim/lib/chakra_shim.js index 24f48775aaf..aa21685977e 100644 --- a/deps/chakrashim/lib/chakra_shim.js +++ b/deps/chakrashim/lib/chakra_shim.js @@ -30,6 +30,7 @@ Object.defineProperty(this, 'Debug', Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor, Object_getOwnPropertyNames = Object.getOwnPropertyNames, Object_keys = Object.keys, + Object_prototype_toString = Object.prototype.toString, Map_keys = Map.prototype.keys, Map_values = Map.prototype.values, Map_entries = Map.prototype.entries, @@ -315,6 +316,45 @@ Object.defineProperty(this, 'Debug', utils.isSetIterator = function(value) { return value[setIteratorProperty] == true; }; + function compareType(o, expectedType) { + return Object_prototype_toString.call(o) === '[object ' + + expectedType + ']'; + }; + utils.isBooleanObject = function(obj) { + return compareType(obj, 'Boolean'); + }; + utils.isDate = function(obj) { + return compareType(obj, 'Date'); + }; + utils.isMap = function(obj) { + return compareType(obj, 'Map'); + }; + utils.isNativeError = function(obj) { + return compareType(obj, 'Error') || + obj instanceof Error || + obj instanceof EvalError || + obj instanceof RangeError || + obj instanceof ReferenceError || + obj instanceof SyntaxError || + obj instanceof TypeError || + obj instanceof URIError; + }; + utils.isPromise = function(obj) { + return compareType(obj, 'Object') && obj instanceof Promise; + }; + utils.isRegExp = function(obj) { + return compareType(obj, 'RegExp'); + }; + utils.isSet = function(obj) { + return compareType(obj, 'Set'); + }; + utils.isStringObject = function(obj) { + return compareType(obj, 'String'); + }; + utils.isNumberObject = function(obj) { + return compareType(obj, 'Number'); + }; + } // patch console diff --git a/deps/chakrashim/src/jsrtcachedpropertyidref.inc b/deps/chakrashim/src/jsrtcachedpropertyidref.inc index 80568fcc0aa..a281293c7ab 100644 --- a/deps/chakrashim/src/jsrtcachedpropertyidref.inc +++ b/deps/chakrashim/src/jsrtcachedpropertyidref.inc @@ -26,6 +26,9 @@ #define DEFSYMBOL(x) #endif +#ifndef DEF_IS_TYPE +#define DEF_IS_TYPE(x) DEF(x) +#endif DEF(apply) DEF(concat) @@ -70,9 +73,6 @@ DEF(getColumnNumber) DEF(getLineNumber) DEF(prototype) DEF(toString) -DEF(isMapIterator) -DEF(isSetIterator) - DEFSYMBOL(self) DEFSYMBOL(__external__) @@ -80,5 +80,19 @@ DEFSYMBOL(__hiddenvalues__) DEFSYMBOL(__isexternal__) DEFSYMBOL(__keepalive__) +DEF_IS_TYPE(isMapIterator) +DEF_IS_TYPE(isSetIterator) +DEF_IS_TYPE(isBooleanObject) +DEF_IS_TYPE(isDate) +DEF_IS_TYPE(isMap) +DEF_IS_TYPE(isNativeError) +DEF_IS_TYPE(isPromise) +DEF_IS_TYPE(isRegExp) +DEF_IS_TYPE(isSet) +DEF_IS_TYPE(isStringObject) +DEF_IS_TYPE(isNumberObject) + + #undef DEF #undef DEFSYMBOL +#undef DEF_IS_TYPE diff --git a/deps/chakrashim/src/jsrtcontextcachedobj.inc b/deps/chakrashim/src/jsrtcontextcachedobj.inc index ebbaf97da9c..1c988ad6228 100644 --- a/deps/chakrashim/src/jsrtcontextcachedobj.inc +++ b/deps/chakrashim/src/jsrtcontextcachedobj.inc @@ -27,21 +27,12 @@ #endif // These global constructors will be cached -DEFTYPE(ArrayBuffer) DEFTYPE(Boolean) DEFTYPE(Date) -DEFTYPE(Error) -DEFTYPE(EvalError) -DEFTYPE(Function) DEFTYPE(Number) DEFTYPE(Object) DEFTYPE(Proxy) -DEFTYPE(RangeError) -DEFTYPE(ReferenceError) -DEFTYPE(RegExp) DEFTYPE(String) -DEFTYPE(SyntaxError) -DEFTYPE(TypeError) DEFTYPE(Uint8Array) DEFTYPE(Uint8ClampedArray) DEFTYPE(Int8Array) @@ -51,10 +42,7 @@ DEFTYPE(Uint32Array) DEFTYPE(Int32Array) DEFTYPE(Float32Array) DEFTYPE(Float64Array) -DEFTYPE(URIError) -DEFTYPE(Promise) -DEFTYPE(Map) -DEFTYPE(Set) + // These prototype functions will be cached/shimmed diff --git a/deps/chakrashim/src/jsrtcontextshim.cc b/deps/chakrashim/src/jsrtcontextshim.cc index 86064f10472..177bcaf0f6c 100644 --- a/deps/chakrashim/src/jsrtcontextshim.cc +++ b/deps/chakrashim/src/jsrtcontextshim.cc @@ -50,6 +50,8 @@ ContextShim * ContextShim::New(IsolateShim * isolateShim, bool exposeGC, globalObjectTemplateInstance); } +#define DEF_IS_TYPE(F) F##Function(JS_INVALID_REFERENCE), + ContextShim::ContextShim(IsolateShim * isolateShim, JsContextRef context, bool exposeGC, @@ -60,19 +62,18 @@ ContextShim::ContextShim(IsolateShim * isolateShim, exposeGC(exposeGC), globalObjectTemplateInstance(globalObjectTemplateInstance), promiseContinuationFunction(JS_INVALID_REFERENCE), +#include "jsrtcachedpropertyidref.inc" +#undef DEF_IS_TYPE cloneObjectFunction(JS_INVALID_REFERENCE), getPropertyNamesFunction(JS_INVALID_REFERENCE), getOwnPropertyDescriptorFunction(JS_INVALID_REFERENCE), getEnumerableNamedPropertiesFunction(JS_INVALID_REFERENCE), getEnumerableIndexedPropertiesFunction(JS_INVALID_REFERENCE), createEnumerationIteratorFunction(JS_INVALID_REFERENCE), - createPropertyDescriptorsEnumerationIteratorFunction( - JS_INVALID_REFERENCE), + createPropertyDescriptorsEnumerationIteratorFunction(JS_INVALID_REFERENCE), getNamedOwnKeysFunction(JS_INVALID_REFERENCE), getIndexedOwnKeysFunction(JS_INVALID_REFERENCE), - getStackTraceFunction(JS_INVALID_REFERENCE), - isMapIteratorFunction(JS_INVALID_REFERENCE), - isSetIteratorFunction(JS_INVALID_REFERENCE) { + getStackTraceFunction(JS_INVALID_REFERENCE) { memset(globalConstructor, 0, sizeof(globalConstructor)); memset(globalPrototypeFunction, 0, sizeof(globalPrototypeFunction)); } @@ -507,10 +508,6 @@ JsValueRef ContextShim::GetDateConstructor() { return globalConstructor[GlobalType::Date]; } -JsValueRef ContextShim::GetRegExpConstructor() { - return globalConstructor[GlobalType::RegExp]; -} - JsValueRef ContextShim::GetProxyConstructor() { return globalConstructor[GlobalType::Proxy]; } @@ -557,64 +554,25 @@ JsValueRef ContextShim::GetCachedShimFunction(CachedPropertyIdRef id, return *func; } -JsValueRef ContextShim::GetCloneObjectFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::cloneObject, - &cloneObjectFunction); -} - -JsValueRef ContextShim::GetGetPropertyNamesFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::getPropertyNames, - &getPropertyNamesFunction); -} - -JsValueRef ContextShim::GetGetEnumerableNamedPropertiesFunction() { - return GetCachedShimFunction( - CachedPropertyIdRef::getEnumerableNamedProperties, - &getEnumerableNamedPropertiesFunction); -} - -JsValueRef ContextShim::GetGetEnumerableIndexedPropertiesFunction() { - return GetCachedShimFunction( - CachedPropertyIdRef::getEnumerableIndexedProperties, - &getEnumerableIndexedPropertiesFunction); -} - -JsValueRef ContextShim::GetCreateEnumerationIteratorFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::createEnumerationIterator, - &createEnumerationIteratorFunction); -} - -JsValueRef -ContextShim::GetCreatePropertyDescriptorsEnumerationIteratorFunction() { - return GetCachedShimFunction( - CachedPropertyIdRef::createPropertyDescriptorsEnumerationIterator, - &createPropertyDescriptorsEnumerationIteratorFunction); -} - -JsValueRef ContextShim::GetGetNamedOwnKeysFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::getNamedOwnKeys, - &getNamedOwnKeysFunction); -} - -JsValueRef ContextShim::GetGetIndexedOwnKeysFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::getIndexedOwnKeys, - &getIndexedOwnKeysFunction); -} - -JsValueRef ContextShim::GetGetStackTraceFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::getStackTrace, - &getStackTraceFunction); -} - -JsValueRef ContextShim::GetIsMapIteratorFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::isMapIterator, - &isMapIteratorFunction); -} - -JsValueRef ContextShim::GetIsSetIteratorFunction() { - return GetCachedShimFunction(CachedPropertyIdRef::isSetIterator, - &isSetIteratorFunction); -} +#define CHAKRASHIM_FUNCTION_GETTER(F) \ +JsValueRef ContextShim::Get##F##Function() { \ +return GetCachedShimFunction(CachedPropertyIdRef::F, \ + &##F##Function); \ +} \ + +CHAKRASHIM_FUNCTION_GETTER(cloneObject) +CHAKRASHIM_FUNCTION_GETTER(getPropertyNames) +CHAKRASHIM_FUNCTION_GETTER(getEnumerableNamedProperties) +CHAKRASHIM_FUNCTION_GETTER(getEnumerableIndexedProperties) +CHAKRASHIM_FUNCTION_GETTER(createEnumerationIterator) +CHAKRASHIM_FUNCTION_GETTER(createPropertyDescriptorsEnumerationIterator) +CHAKRASHIM_FUNCTION_GETTER(getNamedOwnKeys) +CHAKRASHIM_FUNCTION_GETTER(getIndexedOwnKeys) +CHAKRASHIM_FUNCTION_GETTER(getStackTrace) + +#define DEF_IS_TYPE(F) CHAKRASHIM_FUNCTION_GETTER(F) +#include "jsrtcachedpropertyidref.inc" +#undef DEF_IS_TYPE } // namespace jsrt diff --git a/deps/chakrashim/src/jsrtcontextshim.h b/deps/chakrashim/src/jsrtcontextshim.h index 815d6a7cfb3..5e2d050989d 100644 --- a/deps/chakrashim/src/jsrtcontextshim.h +++ b/deps/chakrashim/src/jsrtcontextshim.h @@ -21,7 +21,6 @@ #include namespace jsrt { - class ContextShim { public: // This has the same layout as v8::Context::Scope @@ -79,17 +78,6 @@ class ContextShim { JsValueRef GetReflectObject(); JsValueRef GetReflectFunctionForTrap(ProxyTraps traps); - JsValueRef GetCloneObjectFunction(); - JsValueRef GetGetPropertyNamesFunction(); - JsValueRef GetGetEnumerableNamedPropertiesFunction(); - JsValueRef GetGetEnumerableIndexedPropertiesFunction(); - JsValueRef GetCreateEnumerationIteratorFunction(); - JsValueRef GetCreatePropertyDescriptorsEnumerationIteratorFunction(); - JsValueRef GetGetNamedOwnKeysFunction(); - JsValueRef GetGetIndexedOwnKeysFunction(); - JsValueRef GetGetStackTraceFunction(); - JsValueRef GetIsMapIteratorFunction(); - JsValueRef GetIsSetIteratorFunction(); void * GetAlignedPointerFromEmbedderData(int index); void SetAlignedPointerInEmbedderData(int index, void * value); @@ -138,21 +126,28 @@ class ContextShim { JsValueRef getOwnPropertyDescriptorFunction; JsValueRef promiseContinuationFunction; - - JsValueRef cloneObjectFunction; - JsValueRef getPropertyNamesFunction; - - JsValueRef getEnumerableNamedPropertiesFunction; - JsValueRef getEnumerableIndexedPropertiesFunction; - JsValueRef createEnumerationIteratorFunction; - JsValueRef createPropertyDescriptorsEnumerationIteratorFunction; - JsValueRef getNamedOwnKeysFunction; - JsValueRef getIndexedOwnKeysFunction; - JsValueRef getStackTraceFunction; - JsValueRef isMapIteratorFunction; - JsValueRef isSetIteratorFunction; - std::vector embedderData; + +#define DECLARE_CHAKRASHIM_FUNCTION_GETTER(F) \ +public: \ +JsValueRef Get##F##Function(); \ +private: \ +JsValueRef F##Function; \ + + DECLARE_CHAKRASHIM_FUNCTION_GETTER(cloneObject); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(getPropertyNames); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(getEnumerableNamedProperties); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(getEnumerableIndexedProperties); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(createEnumerationIterator); + DECLARE_CHAKRASHIM_FUNCTION_GETTER + (createPropertyDescriptorsEnumerationIterator); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(getNamedOwnKeys); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(getIndexedOwnKeys); + DECLARE_CHAKRASHIM_FUNCTION_GETTER(getStackTrace); + +#define DEF_IS_TYPE(F) DECLARE_CHAKRASHIM_FUNCTION_GETTER(F) +#include "jsrtcachedpropertyidref.inc" +#undef DEF_IS_TYPE }; } // namespace jsrt diff --git a/deps/chakrashim/src/jsrtutils.cc b/deps/chakrashim/src/jsrtutils.cc index c89b22abd80..218f2bb8d6e 100644 --- a/deps/chakrashim/src/jsrtutils.cc +++ b/deps/chakrashim/src/jsrtutils.cc @@ -250,7 +250,7 @@ JsErrorCode CloneObject(JsValueRef source, JsValueRef target, bool clonePrototype) { JsValueRef cloneObjectFunction = - ContextShim::GetCurrent()->GetCloneObjectFunction(); + ContextShim::GetCurrent()->GetcloneObjectFunction(); JsValueRef resultRef; JsErrorCode error = CallFunction(cloneObjectFunction, @@ -399,28 +399,28 @@ JsErrorCode IsUndefined(JsValueRef value, JsErrorCode GetEnumerableNamedProperties(JsValueRef object, JsValueRef *result) { return CallFunction( - ContextShim::GetCurrent()->GetGetEnumerableNamedPropertiesFunction(), + ContextShim::GetCurrent()->GetgetEnumerableNamedPropertiesFunction(), object, result); } JsErrorCode GetEnumerableIndexedProperties(JsValueRef object, JsValueRef *result) { return CallFunction( - ContextShim::GetCurrent()->GetGetEnumerableIndexedPropertiesFunction(), + ContextShim::GetCurrent()->GetgetEnumerableIndexedPropertiesFunction(), object, result); } JsErrorCode GetIndexedOwnKeys(JsValueRef object, JsValueRef *result) { return CallFunction( - ContextShim::GetCurrent()->GetGetIndexedOwnKeysFunction(), + ContextShim::GetCurrent()->GetgetIndexedOwnKeysFunction(), object, result); } JsErrorCode GetNamedOwnKeys(JsValueRef object, JsValueRef *result) { return CallFunction( - ContextShim::GetCurrent()->GetGetNamedOwnKeysFunction(), + ContextShim::GetCurrent()->GetgetNamedOwnKeysFunction(), object, result); } @@ -437,7 +437,7 @@ JsErrorCode ConcatArray(JsValueRef first, JsErrorCode CreateEnumerationIterator(JsValueRef enumeration, JsValueRef *result) { return CallFunction( - ContextShim::GetCurrent()->GetCreateEnumerationIteratorFunction(), + ContextShim::GetCurrent()->GetcreateEnumerationIteratorFunction(), enumeration, result); } @@ -445,14 +445,14 @@ JsErrorCode CreatePropertyDescriptorsEnumerationIterator(JsValueRef enumeration, JsValueRef *result) { return CallFunction( ContextShim::GetCurrent() - ->GetCreatePropertyDescriptorsEnumerationIteratorFunction(), + ->GetcreatePropertyDescriptorsEnumerationIteratorFunction(), enumeration, result); } JsErrorCode GetPropertyNames(JsValueRef object, JsValueRef *result) { return CallFunction( - ContextShim::GetCurrent()->GetGetPropertyNamesFunction(), + ContextShim::GetCurrent()->GetgetPropertyNamesFunction(), object, result); } @@ -554,20 +554,16 @@ JsErrorCode ToString(JsValueRef ref, return error; } -JsErrorCode IsValueMapIterator(JsValueRef value, - JsValueRef *resultRef) { - return CallFunction( - ContextShim::GetCurrent()->GetIsMapIteratorFunction(), - value, resultRef); -} +#define DEF_IS_TYPE(F) \ +JsErrorCode Call##F##(JsValueRef value, JsValueRef *resultRef) { \ + return CallFunction( \ + ContextShim::GetCurrent()->Get##F##Function(), \ + value, resultRef); \ +} \ -JsErrorCode IsValueSetIterator(JsValueRef value, - JsValueRef *resultRef) { - return CallFunction( - ContextShim::GetCurrent()->GetIsSetIteratorFunction(), - value, resultRef); -} +#include "jsrtcachedpropertyidref.inc" +#undef DEF_IS_TYPE PropertyDescriptorOptionValues GetPropertyDescriptorOptionValue(bool b) { return b ? @@ -741,7 +737,7 @@ JsErrorCode GetPropertyIdFromName(JsValueRef nameRef, if (error == JsErrorInvalidArgument) { error = JsGetPropertyIdFromSymbol(nameRef, idRef); if (error == JsErrorPropertyNotSymbol) { - error = JsErrorInvalidArgument; // Neither String nor Symbol + error = JsErrorInvalidArgument; // Neither String nor Symbol } } } else { diff --git a/deps/chakrashim/src/jsrtutils.h b/deps/chakrashim/src/jsrtutils.h index 0db60dec3b9..b883fc6ffbb 100644 --- a/deps/chakrashim/src/jsrtutils.h +++ b/deps/chakrashim/src/jsrtutils.h @@ -217,11 +217,12 @@ JsErrorCode ToString(JsValueRef ref, const wchar_t** str, bool alreadyString = false); -JsErrorCode IsValueMapIterator(JsValueRef value, - JsValueRef *resultRef); +#define DEF_IS_TYPE(F) \ +JsErrorCode Call##F##(JsValueRef value, \ +JsValueRef *resultRef); \ -JsErrorCode IsValueSetIterator(JsValueRef value, - JsValueRef *resultRef); +#include "jsrtcachedpropertyidref.inc" +#undef DEF_IS_TYPE JsValueRef CALLBACK CollectGarbage(JsValueRef callee, bool isConstructCall, diff --git a/deps/chakrashim/src/v8objecttemplate.cc b/deps/chakrashim/src/v8objecttemplate.cc index dd0063ef543..6c5d54af627 100644 --- a/deps/chakrashim/src/v8objecttemplate.cc +++ b/deps/chakrashim/src/v8objecttemplate.cc @@ -285,6 +285,7 @@ JsValueRef CALLBACK Utils::SetCallback(JsValueRef callee, return GetFalse(); } + Local setCallbackResult; if (isPropIntType) { if (objectData->indexedPropertySetter) { PropertyCallbackInfo info( @@ -293,13 +294,12 @@ JsValueRef CALLBACK Utils::SetCallback(JsValueRef callee, /*holder*/reinterpret_cast(object)); objectData->indexedPropertySetter( index, reinterpret_cast(value), info); - return reinterpret_cast(info.GetReturnValue().Get()); + + setCallbackResult = info.GetReturnValue().Get(); } else { // use default JS behavior if (jsrt::SetIndexedProperty(object, index, value) != JsNoError) { return GetFalse(); } - - return GetTrue(); } } else { if (objectData->namedPropertySetter) { @@ -309,15 +309,24 @@ JsValueRef CALLBACK Utils::SetCallback(JsValueRef callee, /*holder*/reinterpret_cast(object)); objectData->namedPropertySetter( reinterpret_cast(prop), reinterpret_cast(value), info); - return reinterpret_cast(info.GetReturnValue().Get()); + + setCallbackResult = info.GetReturnValue().Get(); } else { // use default JS behavior if (jsrt::SetProperty(object, prop, value) != JsNoError) { return GetFalse(); } - - return GetTrue(); } } + + /* Per NamedPropertySetter documentation : + Returns the value if the setter intercepts the request. + Otherwise, returns an empty handle. + */ + if (setCallbackResult.IsEmpty()) { + return GetFalse(); + } else { + return GetTrue(); + } } JsValueRef CALLBACK Utils::DeletePropertyCallback(JsValueRef callee, @@ -344,6 +353,7 @@ JsValueRef CALLBACK Utils::DeletePropertyCallback(JsValueRef callee, return GetFalse(); } + Local deleteCallbackResult; if (isPropIntType) { if (objectData->indexedPropertyDeleter != nullptr) { PropertyCallbackInfo info( @@ -351,13 +361,13 @@ JsValueRef CALLBACK Utils::DeletePropertyCallback(JsValueRef callee, reinterpret_cast(object), /*holder*/reinterpret_cast(object)); objectData->indexedPropertyDeleter(index, info); - return reinterpret_cast(info.GetReturnValue().Get()); + + deleteCallbackResult = info.GetReturnValue().Get(); + } else { if (DeleteIndexedProperty(object, index) != JsNoError) { return GetFalse(); } - - return GetTrue(); } } else { if (objectData->namedPropertyDeleter != nullptr) { @@ -366,13 +376,27 @@ JsValueRef CALLBACK Utils::DeletePropertyCallback(JsValueRef callee, reinterpret_cast(object), /*holder*/reinterpret_cast(object)); objectData->namedPropertyDeleter(reinterpret_cast(prop), info); - return reinterpret_cast(info.GetReturnValue().Get()); + + deleteCallbackResult = info.GetReturnValue().Get(); } else { // use default JS behavior if (jsrt::DeleteProperty(object, prop, &result) != JsNoError) { return GetFalse(); } + } + } - return result; + /* Per NamedPropertyDeleter documentation : + Returns a non-empty handle if the deleter intercepts the request. + The return value is true if the property could be deleted and false + otherwise. + */ + if (deleteCallbackResult.IsEmpty()) { + return GetFalse(); + } else { + if (deleteCallbackResult->BooleanValue()) { + return GetTrue(); + } else { + return GetFalse(); } } } diff --git a/deps/chakrashim/src/v8stacktrace.cc b/deps/chakrashim/src/v8stacktrace.cc index 149a1acac15..4da2720284d 100644 --- a/deps/chakrashim/src/v8stacktrace.cc +++ b/deps/chakrashim/src/v8stacktrace.cc @@ -33,7 +33,7 @@ Local StackTrace::CurrentStackTrace(Isolate* isolate, IsolateShim* iso = IsolateShim::FromIsolate(isolate); ContextShim* contextShim = iso->GetCurrentContextShim(); - JsValueRef getStackTrace = contextShim->GetGetStackTraceFunction(); + JsValueRef getStackTrace = contextShim->GetgetStackTraceFunction(); JsValueRef stackTrace; if (jsrt::CallFunction(getStackTrace, &stackTrace) != JsNoError) { return Local(); diff --git a/deps/chakrashim/src/v8value.cc b/deps/chakrashim/src/v8value.cc index d0f44df878e..21c2ab18a73 100644 --- a/deps/chakrashim/src/v8value.cc +++ b/deps/chakrashim/src/v8value.cc @@ -33,11 +33,6 @@ static bool IsOfType(const Value* ref, JsValueType type) { return valueType == type; } -static bool IsOfType(const Value* ref, ContextShim::GlobalType index) { - return jsrt::InstanceOf(const_cast(ref), - ContextShim::GetCurrent()->GetGlobalType(index)); -} - bool Value::IsUndefined() const { return IsOfType(this, JsValueType::JsUndefined); } @@ -157,68 +152,28 @@ bool Value::IsUint32() const { return trunc(value) == value; } -bool Value::IsDate() const { - return IsOfType(this, ContextShim::GlobalType::Date); -} - -bool Value::IsBooleanObject() const { - return IsOfType(this, ContextShim::GlobalType::Boolean); -} - -bool Value::IsNumberObject() const { - return IsOfType(this, ContextShim::GlobalType::Number); -} - -bool Value::IsStringObject() const { - return IsOfType(this, ContextShim::GlobalType::String); -} -bool Value::IsMap() const -{ - return IsOfType(this, ContextShim::GlobalType::Map); -} - -bool Value::IsSet() const -{ - return IsOfType(this, ContextShim::GlobalType::Set); -} - -bool Value::IsNativeError() const { - return IsOfType(this, ContextShim::GlobalType::Error) - || IsOfType(this, ContextShim::GlobalType::EvalError) - || IsOfType(this, ContextShim::GlobalType::RangeError) - || IsOfType(this, ContextShim::GlobalType::ReferenceError) - || IsOfType(this, ContextShim::GlobalType::SyntaxError) - || IsOfType(this, ContextShim::GlobalType::TypeError) - || IsOfType(this, ContextShim::GlobalType::URIError); -} - -bool Value::IsRegExp() const { - return IsOfType(this, ContextShim::GlobalType::RegExp); -} - -bool Value::IsMapIterator() const { - JsValueRef resultRef = JS_INVALID_REFERENCE; - JsErrorCode errorCode = jsrt::IsValueMapIterator( - const_cast(this), &resultRef); - if (errorCode != JsNoError) { - return false; - } - return Local(resultRef)->BooleanValue(); -} - -bool Value::IsSetIterator() const { - JsValueRef resultRef = JS_INVALID_REFERENCE; - JsErrorCode errorCode = jsrt::IsValueSetIterator( - const_cast(this), &resultRef); - if (errorCode != JsNoError) { - return false; - } - return Local(resultRef)->BooleanValue(); -} - -bool Value::IsPromise() const { - return IsOfType(this, ContextShim::GlobalType::Promise); -} +#define IS_TYPE_FUNCTION(v8ValueFunc, chakrashimFunc) \ +bool Value::##v8ValueFunc##() const { \ +JsValueRef resultRef = JS_INVALID_REFERENCE; \ +JsErrorCode errorCode = jsrt::Call##chakrashimFunc##( \ + const_cast(this), &resultRef); \ +if (errorCode != JsNoError) { \ + return false; \ +} \ +return Local(resultRef)->BooleanValue(); \ +} \ + +IS_TYPE_FUNCTION(IsBooleanObject, isBooleanObject) +IS_TYPE_FUNCTION(IsDate, isDate) +IS_TYPE_FUNCTION(IsMap, isMap) +IS_TYPE_FUNCTION(IsNativeError, isNativeError) +IS_TYPE_FUNCTION(IsPromise, isPromise) +IS_TYPE_FUNCTION(IsRegExp, isRegExp) +IS_TYPE_FUNCTION(IsSet, isSet) +IS_TYPE_FUNCTION(IsStringObject, isStringObject) +IS_TYPE_FUNCTION(IsNumberObject, isNumberObject) +IS_TYPE_FUNCTION(IsMapIterator, isMapIterator) +IS_TYPE_FUNCTION(IsSetIterator, isSetIterator) MaybeLocal Value::ToBoolean(Local context) const { JsValueRef value; diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 8cb42b860d5..3535f829426 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -194,7 +194,10 @@ function error_test() { chakracore : /^SyntaxError: Invalid usage of 'eval' in strict mode/}) }, { client: client_unix, send: '(function() { "use strict"; if (true) function f() { } })()', - expect: /^SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function/ }, + expect: common.engineSpecificMessage({ + v8 : /^SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function/, + chakracore : /^SyntaxError: Syntax error/}) + }, // Named functions can be used: { client: client_unix, send: 'function blah() { return 1; }', expect: prompt_unix },