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

Commit

Permalink
chakrashim, test: Chakrashim fixes
Browse files Browse the repository at this point in the history
Below things were fixed in chakrashim
* There was unnecessary assert added in previous commit for
`PropertyDescriptor`. Removed it.
* We wanted to cache `Object.getOwnPropertyDescriptor` but while
initializing the shim we did by extracting `getOwnPropertyDescriptor`
property from `Object.prototype` which was `undefined`. This was not
broken so far because it was never used. Node started using this
feature and hence realized it. Fixed it by calling `JsGetOwnPropertyDescriptor`
instead. This has performance hit slightly because now property names
has to be converted to property id before calling Jsrt api. Earlier
this was taken care by runtime.

Below things were fixed for unit test
* Error message difference
* There was a test case marked as known issue but that doesn't fail for
chakracore. Skipping its execution so it doesn't get tagged as FAILED.
  • Loading branch information
kunalspathak committed Feb 26, 2017
1 parent 233a053 commit ed2964b
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 40 deletions.
1 change: 0 additions & 1 deletion deps/chakrashim/src/jsrtcontextcachedobj.inc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ DEFTYPE(Float64Array)


// These prototype functions will be cached/shimmed
DEFMETHOD(Object, getOwnPropertyDescriptor)
DEFMETHOD(Object, hasOwnProperty)
DEFMETHOD(Object, toString)
DEFMETHOD(String, concat)
Expand Down
7 changes: 5 additions & 2 deletions deps/chakrashim/src/jsrtcontextshim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,12 @@ DECLARE_GETOBJECT(DateConstructor,
globalConstructor[GlobalType::Date])
DECLARE_GETOBJECT(ProxyConstructor,
globalConstructor[GlobalType::Proxy])
DECLARE_GETOBJECT(GetOwnPropertyDescriptorFunction,
DECLARE_GETOBJECT(HasOwnPropertyFunction,
globalPrototypeFunction[GlobalPrototypeFunction
::Object_getOwnPropertyDescriptor])
::Object_hasOwnProperty])
DECLARE_GETOBJECT(ToStringFunction,
globalPrototypeFunction[GlobalPrototypeFunction
::Object_toString])
DECLARE_GETOBJECT(StringConcatFunction,
globalPrototypeFunction[GlobalPrototypeFunction
::String_concat])
Expand Down
4 changes: 3 additions & 1 deletion deps/chakrashim/src/jsrtcontextshim.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class ContextShim {
JsValueRef GetRegExpConstructor();
JsValueRef GetProxyConstructor();
JsValueRef GetGlobalType(GlobalType index);
JsValueRef GetGetOwnPropertyDescriptorFunction();

JsValueRef GetHasOwnPropertyFunction();
JsValueRef GetToStringFunction();
JsValueRef GetStringConcatFunction();
JsValueRef GetArrayPushFunction();
JsValueRef GetGlobalPrototypeFunction(GlobalPrototypeFunction index);
Expand Down
16 changes: 11 additions & 5 deletions deps/chakrashim/src/jsrtutils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ JsErrorCode HasOwnProperty(JsValueRef object,
JsValueRef prop,
JsValueRef *result) {
JsValueRef hasOwnPropertyFunction =
ContextShim::GetCurrent()->GetGlobalPrototypeFunction(
ContextShim::GlobalPrototypeFunction::Object_hasOwnProperty);
ContextShim::GetCurrent()->GetHasOwnPropertyFunction();

JsValueRef args[] = { object, prop };
return JsCallFunction(hasOwnPropertyFunction, args, _countof(args), result);
Expand All @@ -283,9 +282,16 @@ JsErrorCode HasOwnProperty(JsValueRef object,
JsErrorCode GetOwnPropertyDescriptor(JsValueRef ref,
JsValueRef prop,
JsValueRef* result) {
return CallFunction(
ContextShim::GetCurrent()->GetGetOwnPropertyDescriptorFunction(),
ref, prop, result);

JsPropertyIdRef idRef;
JsErrorCode error;

error = GetPropertyIdFromName(prop, &idRef);
if (error != JsNoError) {
return error;
}

return JsGetOwnPropertyDescriptor(ref, idRef, result);
}

JsErrorCode IsZero(JsValueRef value,
Expand Down
3 changes: 1 addition & 2 deletions deps/chakrashim/src/v8object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,7 @@ bool Object::SetPrototype(Handle<Value> prototype) {

MaybeLocal<String> Object::ObjectProtoToString(Local<Context> context) {
ContextShim* contextShim = ContextShim::GetCurrent();
JsValueRef toString = contextShim->GetGlobalPrototypeFunction(
ContextShim::GlobalPrototypeFunction::Object_toString);
JsValueRef toString = contextShim->GetToStringFunction();

JsValueRef result;
JsValueRef args[] = { this };
Expand Down
2 changes: 0 additions & 2 deletions deps/chakrashim/src/v8propertydescriptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,10 @@ Local<Value> PropertyDescriptor::value() const {
}

Local<Value> PropertyDescriptor::get() const {
CHAKRA_ASSERT(private_->has_get());
return Local<Value>::New(private_->get);
}

Local<Value> PropertyDescriptor::set() const {
CHAKRA_ASSERT(private_->has_set());
return Local<Value>::New(private_->set);
}

Expand Down
3 changes: 2 additions & 1 deletion test/known_issues/known_issues.status
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ test-stdout-buffer-flush-on-exit: SKIP

[$jsEngine==chakracore]
test-vm-function-redefinition : SKIP
test-vm-inherited_properties : SKIP
test-vm-inherited_properties : SKIP
test-vm-data-property-writable : SKIP
2 changes: 1 addition & 1 deletion test/message/error_exit.chakracore.out
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Exiting with code=1
AssertionError: 1 == 2
AssertionError: 1 === 2
at Anonymous function (*test*message*error_exit.js:*:*)
at Module.prototype._compile (module.js:*:*)
at Module._extensions[.js] (module.js:*:*)
Expand Down
7 changes: 5 additions & 2 deletions test/parallel/test-http-outgoing-proto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');

const http = require('http');
Expand Down Expand Up @@ -62,7 +62,10 @@ assert.throws(() => {
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers();
}, /^TypeError: Cannot convert undefined or null to object$/);
}, common.engineSpecificMessage({
v8: /^TypeError: Cannot convert undefined or null to object$/,
chakracore: /^TypeError: Object expected/
}));

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
Expand Down
5 changes: 4 additions & 1 deletion test/parallel/test-internal-util-decorate-error-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ assert.strictEqual(obj.stack, undefined);

// Verify that the stack is decorated when possible
function checkStack(stack) {
const matches = stack.match(/var foo bar;/g);
const matches = stack.match(common.engineSpecificMessage({
v8: /var foo bar;/g,
chakracore: /Expected ';'/g // chakra does not show source
}));
assert.strictEqual(Array.isArray(matches), true);
assert.strictEqual(matches.length, 1);
}
Expand Down
30 changes: 17 additions & 13 deletions test/parallel/test-url-format-whatwg.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

require('../common');
const common = require('../common');
const assert = require('assert');
const url = require('url');
const URL = url.URL;
Expand Down Expand Up @@ -76,20 +76,24 @@ assert.strictEqual(
'http://xn--lck1c3crb1723bpq4a.com/a?a=b#c'
);

assert.strictEqual(
// Unicode conversion in node code is dependent on
// v8's i18n support which is disabled for chakracore
if (!common.isChakraEngine) {
assert.strictEqual(
url.format(myURL, {unicode: true}),
'http://理容ナカムラ.com/a?a=b#c'
);

assert.strictEqual(
url.format(myURL, {unicode: 1}),
'http://理容ナカムラ.com/a?a=b#c'
);

assert.strictEqual(
url.format(myURL, {unicode: {}}),
'http://理容ナカムラ.com/a?a=b#c'
);
);

assert.strictEqual(
url.format(myURL, {unicode: 1}),
'http://理容ナカムラ.com/a?a=b#c'
);

assert.strictEqual(
url.format(myURL, {unicode: {}}),
'http://理容ナカムラ.com/a?a=b#c'
);
}

assert.strictEqual(
url.format(myURL, {unicode: false}),
Expand Down
22 changes: 17 additions & 5 deletions test/parallel/test-whatwg-url-properties.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Flags: --expose-internals
'use strict';

require('../common');
const common = require('../common');
const URL = require('url').URL;
const assert = require('assert');
const urlToOptions = require('internal/url').urlToOptions;
Expand Down Expand Up @@ -44,8 +44,14 @@ assert.strictEqual(url.searchParams, oldParams); // [SameObject]
// non-writable property should throw.
// Note: this error message is subject to change in V8 updates
assert.throws(() => url.origin = 'http://foo.bar.com:22',
new RegExp('TypeError: Cannot set property origin of' +
' \\[object URL\\] which has only a getter'));
new RegExp(
common.engineSpecificMessage({
v8: 'TypeError: Cannot set property origin of' +
' \\[object URL\\] which has only a getter',
chakracore: 'TypeError: Assignment to read-only' +
' properties is not allowed in strict mode'
})
));
assert.strictEqual(url.origin, 'http://foo.bar.com:21');
assert.strictEqual(url.toString(),
'http://user:[email protected]:21/aaa/zzz?l=25#test');
Expand Down Expand Up @@ -120,8 +126,14 @@ assert.strictEqual(url.hash, '#abcd');
// non-writable property should throw.
// Note: this error message is subject to change in V8 updates
assert.throws(() => url.searchParams = '?k=88',
new RegExp('TypeError: Cannot set property searchParams of' +
' \\[object URL\\] which has only a getter'));
new RegExp(
common.engineSpecificMessage({
v8: 'TypeError: Cannot set property searchParams of' +
' \\[object URL\\] which has only a getter',
chakracore: 'TypeError: Assignment to read-only properties' +
' is not allowed in strict mode'
})
));
assert.strictEqual(url.searchParams, oldParams);
assert.strictEqual(url.toString(),
'https://user2:[email protected]:23/aaa/bbb?k=99#abcd');
Expand Down
5 changes: 5 additions & 0 deletions test/sequential/test-fs-readfile-tostring-fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ stream.end();
stream.on('finish', common.mustCall(function() {
// make sure that the toString does not throw an error
fs.readFile(file, 'utf8', common.mustCall(function(err, buf) {
// Skip 'toString()' check for chakra engine because it verifies limit of v8
// specific kStringMaxLength variable.
if (common.isChakraEngine) {
return;
}
assert.ok(err instanceof Error);
assert.strictEqual('"toString()" failed', err.message);
assert.strictEqual(buf, undefined);
Expand Down
6 changes: 2 additions & 4 deletions test/sequential/test-module-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ assert.throws(
function() {
require('../fixtures/packages/invalid');
},
new RegExp(
'^SyntaxError: Error parsing \\S+: ' +
new RegExp('^SyntaxError: Error parsing \\S+: ') +
common.engineSpecificMessage({
v8: 'Unexpected token , in JSON at position 1$',
chakraCore: 'JSON.parse Error: Invalid character at position:2$'
chakracore: 'JSON.parse Error: Invalid character at position:2$'
})
)
);

assert.strictEqual(require('../fixtures/packages/index').ok, 'ok',
Expand Down

0 comments on commit ed2964b

Please sign in to comment.