Skip to content

Commit f71f661

Browse files
committed
Prefer 'in' over 'hasOwnProperty' when safe.
- Static '@' keywords should be safe to use with 'in'.
1 parent c28d21d commit f71f661

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/context.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,12 +1284,12 @@ api.getContextValue = (ctx, key, type) => {
12841284
}
12851285

12861286
// get default language
1287-
if(type === '@language' && ctx.hasOwnProperty(type)) {
1287+
if(type === '@language' && type in ctx) {
12881288
return ctx[type];
12891289
}
12901290

12911291
// get default direction
1292-
if(type === '@direction' && ctx.hasOwnProperty(type)) {
1292+
if(type === '@direction' && type in ctx) {
12931293
return ctx[type];
12941294
}
12951295

lib/frame.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ api.frame = (state, subjects, frame, parent, property = null) => {
271271
// skip keywords
272272
if(prop === '@type') {
273273
if(!types.isObject(frame[prop][0]) ||
274-
!frame[prop][0].hasOwnProperty('@default')) {
274+
!('@default' in frame[prop][0])) {
275275
continue;
276276
}
277277
// allow through default types
@@ -344,7 +344,7 @@ api.cleanupNull = (input, options) => {
344344

345345
if(types.isObject(input)) {
346346
// handle in-memory linked nodes
347-
if(input.hasOwnProperty('@id')) {
347+
if('@id' in input) {
348348
const id = input['@id'];
349349
if(options.link.hasOwnProperty(id)) {
350350
const idx = options.link[id].indexOf(input);
@@ -451,7 +451,7 @@ function _validateFrame(frame) {
451451
'jsonld.SyntaxError', {frame});
452452
}
453453

454-
if(frame[0].hasOwnProperty('@id')) {
454+
if('@id' in frame[0]) {
455455
for(const id of util.asArray(frame[0]['@id'])) {
456456
// @id must be wildcard or an IRI
457457
if(!(types.isObject(id) || url.isAbsolute(id)) ||
@@ -463,7 +463,7 @@ function _validateFrame(frame) {
463463
}
464464
}
465465

466-
if(frame[0].hasOwnProperty('@type')) {
466+
if('@type' in frame[0]) {
467467
for(const type of util.asArray(frame[0]['@type'])) {
468468
// @id must be wildcard or an IRI
469469
if(!(types.isObject(type) || url.isAbsolute(type)) ||
@@ -720,7 +720,7 @@ function _cleanupPreserve(input, options) {
720720
}
721721

722722
// handle in-memory linked nodes
723-
if(input.hasOwnProperty('@id')) {
723+
if('@id' in input) {
724724
const id = input['@id'];
725725
if(options.link.hasOwnProperty(id)) {
726726
const idx = options.link[id].indexOf(input);

0 commit comments

Comments
 (0)