Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
test: fix util.types test for Node-ChakraCore
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhorton committed Mar 8, 2018
1 parent 597adc1 commit 1e9ba64
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 60 deletions.
5 changes: 1 addition & 4 deletions deps/chakrashim/include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,7 @@ class V8_EXPORT Value : public Data {
bool IsFloat32Array() const;
bool IsFloat64Array() const;
bool IsDataView() const;
bool IsSharedArrayBuffer() const {
// CHAKRA-TODO Not implemented
return false;
}
bool IsSharedArrayBuffer() const;
bool IsMapIterator() const;
bool IsSetIterator() const;
bool IsMap() const;
Expand Down
62 changes: 12 additions & 50 deletions deps/chakrashim/lib/chakra_shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
const Object_setPrototypeOf = Object.setPrototypeOf;
const Reflect_apply = Reflect.apply;
const Reflect_construct = Reflect.construct;
const Map_keys = Map.prototype.keys;
const Map_values = Map.prototype.values;
const Map_entries = Map.prototype.entries;
const Set_entries = Set.prototype.entries;
const Set_values = Set.prototype.values;
const Symbol_keyFor = Symbol.keyFor;
const Symbol_for = Symbol.for;
const Global_ParseInt = parseInt;
Expand Down Expand Up @@ -324,41 +319,6 @@
Error.captureStackTrace = captureStackTrace;
}

const mapIteratorProperty = 'MapIteratorIndicator';
function patchMapIterator() {
const originalMapMethods = [];
originalMapMethods.push(['entries', Map_entries]);
originalMapMethods.push(['values', Map_values]);
originalMapMethods.push(['keys', Map_keys]);

originalMapMethods.forEach(function(pair) {
Map.prototype[pair[0]] = function() {
const result = pair[1].apply(this);
Object_defineProperty(
result, mapIteratorProperty,
{ value: true, enumerable: false, writable: false });
return result;
};
});
}

const setIteratorProperty = 'SetIteratorIndicator';
function patchSetIterator() {
const originalSetMethods = [];
originalSetMethods.push(['entries', Set_entries]);
originalSetMethods.push(['values', Set_values]);

originalSetMethods.forEach(function(pair) {
Set.prototype[pair[0]] = function() {
const result = pair[1].apply(this);
Object_defineProperty(
result, setIteratorProperty,
{ value: true, enumerable: false, writable: false });
return result;
};
});
}

// Ensure global Debug object if not already exists, and patch it.
function ensureDebug(otherGlobal) {
if (!global.Debug) {
Expand Down Expand Up @@ -535,19 +495,19 @@
return captureStackTrace({}, undefined)();
};

utils.isMapIterator = function(value) {
return value[mapIteratorProperty] === true;
};

utils.isSetIterator = function(value) {
return value[setIteratorProperty] === true;
};

function compareType(o, expectedType) {
return Object_prototype_toString.call(o) === '[object ' +
expectedType + ']';
}

utils.isMapIterator = function(obj) {
return compareType(obj, 'Map Iterator');
};

utils.isSetIterator = function(obj) {
return compareType(obj, 'Set Iterator');
};

utils.isBooleanObject = function(obj) {
return compareType(obj, 'Boolean');
};
Expand Down Expand Up @@ -627,6 +587,10 @@
return compareType(obj, 'String') || compareType(obj, 'Symbol');
};

utils.isSharedArrayBuffer = function(obj) {
return compareType(obj, 'SharedArrayBuffer');
};

utils.getSymbolKeyFor = function(symbol) {
return Symbol_keyFor(symbol);
};
Expand Down Expand Up @@ -707,8 +671,6 @@

patchErrorTypes();
patchErrorStack();
patchMapIterator();
patchSetIterator();

patchUtils(keepAlive);
});
1 change: 1 addition & 0 deletions deps/chakrashim/src/jsrtcachedpropertyidref.inc
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ DEF_IS_TYPE(isWeakMap)
DEF_IS_TYPE(isWeakSet)
DEF_IS_TYPE(isSymbolObject)
DEF_IS_TYPE(isName)
DEF_IS_TYPE(isSharedArrayBuffer)


#undef DEF
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/src/v8value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ IS_TYPE_FUNCTION(IsWeakMap, isWeakMap)
IS_TYPE_FUNCTION(IsWeakSet, isWeakSet)
IS_TYPE_FUNCTION(IsSymbolObject, isSymbolObject)
IS_TYPE_FUNCTION(IsName, isName)
IS_TYPE_FUNCTION(IsSharedArrayBuffer, isSharedArrayBuffer)

MaybeLocal<Boolean> Value::ToBoolean(Local<Context> context) const {
JsValueRef value;
Expand Down
10 changes: 5 additions & 5 deletions lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

if (process.jsEngine === 'chakracore') {
// This file contains the V8-specific "%<function>" syntax for accessing
// private functions. This is not supported on ChakraCore and causes a
// parser failure. Inject a cache entry to prevent the file from being
// parsed.
// private functions. This is not supported on ChakraCore and causes a
// parser failure. Inject a cache entry to prevent the file from being
// parsed. Return an array to mimmick behavior (required by util.inspect)
NativeModule._cache['internal/v8'] = {
loaded: true,
exports: {
previewMapIterator: function() {},
previewSetIterator: function() {},
previewMapIterator: function() { return []; },
previewSetIterator: function() { return []; },
},
};
}
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-util-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ for (const [ value, _method ] of [
{ value: 'foo' }) ],
[ new DataView(new ArrayBuffer()) ],
[ new SharedArrayBuffer() ],
[ new Proxy({}, {}), 'isProxy' ],
// Node-ChakraCore does not support util.types.isProxy() due to
// Microsoft/ChakraCore#950 and node/node-chakracore#488
!common.isChakraEngine ? [ new Proxy({}, {}), 'isProxy' ] : [ new Date() ],
[ new WebAssembly.Module(wasmBuffer), 'isWebAssemblyCompiledModule' ],
]) {
const method = _method || `is${value.constructor.name}`;
Expand Down

0 comments on commit 1e9ba64

Please sign in to comment.