Skip to content

Commit

Permalink
merge with devel
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Apr 23, 2019
2 parents 5808fc7 + 497a681 commit 41862f5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.4
### Bug fixes
* fix accessing props on native objects like Object function [#6](https://github.com/jcubic/lips/issues/6)

## 0.10.3
### Bug fixes
* fix print that get stdout from global env not from user one + better babel fix added in 0.10.1
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## LIPS is Pretty Simple

[![npm](https://img.shields.io/badge/npm-0.10.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=master&a4db275d1e4999739532a8facda5339175db2e71)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=master&4b1fff165354dc9dcd90095d14379037)](https://coveralls.io/github/jcubic/lips?branch=master)
[![npm](https://img.shields.io/badge/npm-DEV-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
[![travis](https://travis-ci.org/jcubic/jquery.terminal.svg?branch=devel&5808fc794cc5ced0d6d8c100d8e5dbeb9c31f564)](https://travis-ci.org/jcubic/jquery.terminal)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&4b1fff165354dc9dcd90095d14379037)](https://coveralls.io/github/jcubic/lips?branch=devel)


LIPS is very simple Lisp, similar to Scheme written in JavaScript.
Expand Down
61 changes: 47 additions & 14 deletions dist/lips.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**@license
* LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. 0.10.3
* LIPS is Pretty Simple - simple scheme like lisp in JavaScript - v. DEV
*
* Copyright (c) 2018-2019 Jakub T. Jankiewicz <https://jcubic.pl/me>
* Released under the MIT license
Expand All @@ -21,7 +21,7 @@
* http://javascript.nwbox.com/ContentLoaded/
* http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
*
* build: Tue, 23 Apr 2019 07:59:38 +0000
* build: Tue, 23 Apr 2019 10:39:29 +0000
*/
(function () {
'use strict';
Expand Down Expand Up @@ -2203,7 +2203,7 @@ function _typeof(obj) {


function isNativeFunction(fn) {
return typeof fn === 'function' && fn.toString().match(/\{\s*\[native code\]\s*\}/);
return typeof fn === 'function' && fn.toString().match(/\{\s*\[native code\]\s*\}/) && !fn.name.match(/^bound /);
} // ----------------------------------------------------------------------


Expand Down Expand Up @@ -2279,6 +2279,24 @@ function _typeof(obj) {

return obj;
} // ----------------------------------------------------------------------
// :: function bind fn with context but it also move all props
// :: mostly used for Object function
// ----------------------------------------------------------------------


function filterFnNames(name) {
return !['name', 'length'].includes(name);
} // ----------------------------------------------------------------------


function bindWithProps(fn, context) {
var bound = fn.bind(context);
var props = Object.getOwnPropertyNames(fn).filter(filterFnNames);
props.forEach(function (prop) {
bound[prop] = fn[prop];
});
return bound;
} // ----------------------------------------------------------------------


function setFnLength(fn, length) {
Expand Down Expand Up @@ -2522,7 +2540,7 @@ function _typeof(obj) {
var value = obj[name];

if (typeof value === 'function') {
value = value.bind(obj);
value = bindWithProps(value, obj);
}

obj = value;
Expand Down Expand Up @@ -2870,11 +2888,16 @@ function _typeof(obj) {
}

if (typeof value === 'function') {
if (weak) {
return weakBind(value, context);
}
// bind only functions that are not binded for case:
// (let ((x Object)) (. x 'keys))
// second x access is already bound when accessing Object
if (!value.name.match(/^bound /)) {
if (weak) {
return weakBind(value, context);
}

return value.bind(context);
return value.bind(context);
}
}

return value;
Expand All @@ -2895,13 +2918,13 @@ function _typeof(obj) {
var type = _typeof(root[name]);

if (type === 'function') {
// this is maily done for console.log
if (isNativeFunction(root[name])) {
// hard bind of native functions
return root[name].bind(root);
} else {
return root[name];
// hard bind of native functions with props for Object
// hard because of console.log
return bindWithProps(root[name], root);
}

return root[name];
} else if (type !== 'undefined') {
return root[name];
}
Expand Down Expand Up @@ -4566,6 +4589,16 @@ function _typeof(obj) {
error: error
});

if (dynamic_scope) {
arg = unpromise(arg, function (arg) {
if (typeof arg === 'function' && isNativeFunction(arg)) {
return arg.bind(dynamic_scope);
}

return arg;
});
}

args.push(arg);
node = node.cdr;
} else {
Expand Down Expand Up @@ -4863,7 +4896,7 @@ function _typeof(obj) {


return {
version: '0.10.3',
version: 'DEV',
exec: exec,
parse: parse,
tokenize: tokenize,
Expand Down
6 changes: 3 additions & 3 deletions dist/lips.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/hyper.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="https://unpkg.com/hyperapp@1.x.x"></script>
<script src="../dist/lips.js"></script>
<script src="../src/lips.js"></script>
</head>
<body>
<div id="app"></div>
Expand Down
45 changes: 33 additions & 12 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@
// ----------------------------------------------------------------------
function isNativeFunction(fn) {
return typeof fn === 'function' &&
fn.toString().match(/\{\s*\[native code\]\s*\}/);
fn.toString().match(/\{\s*\[native code\]\s*\}/) &&
!fn.name.match(/^bound /);
}
// ----------------------------------------------------------------------
function isPromise(o) {
Expand Down Expand Up @@ -1126,6 +1127,22 @@
return obj;
}
// ----------------------------------------------------------------------
// :: function bind fn with context but it also move all props
// :: mostly used for Object function
// ----------------------------------------------------------------------
function filterFnNames(name) {
return !['name', 'length'].includes(name);
}
// ----------------------------------------------------------------------
function bindWithProps(fn, context) {
const bound = fn.bind(context);
const props = Object.getOwnPropertyNames(fn).filter(filterFnNames);
props.forEach(prop => {
bound[prop] = fn[prop];
});
return bound;
}
// ----------------------------------------------------------------------
function setFnLength(fn, length) {
try {
Object.defineProperty(fn, 'length', {
Expand Down Expand Up @@ -1298,7 +1315,7 @@
var name = arg instanceof Symbol ? arg.name : arg;
var value = obj[name];
if (typeof value === 'function') {
value = value.bind(obj);
value = bindWithProps(value, obj);
}
obj = value;
}
Expand Down Expand Up @@ -1613,10 +1630,15 @@
return LNumber(value);
}
if (typeof value === 'function') {
if (weak) {
return weakBind(value, context);
// bind only functions that are not binded for case:
// (let ((x Object)) (. x 'keys))
// second x access is already bound when accessing Object
if (!value.name.match(/^bound /)) {
if (weak) {
return weakBind(value, context);
}
return value.bind(context);
}
return value.bind(context);
}
return value;
}
Expand All @@ -1632,13 +1654,12 @@
if (name) {
var type = typeof root[name];
if (type === 'function') {
// this is maily done for console.log
if (isNativeFunction(root[name])) {
// hard bind of native functions
return root[name].bind(root);
} else {
return root[name];
// hard bind of native functions with props for Object
// hard because of console.log
return bindWithProps(root[name], root);
}
return root[name];
} else if (type !== 'undefined') {
return root[name];
}
Expand Down Expand Up @@ -3292,9 +3313,9 @@
while (true) {
if (node instanceof Pair && !isEmptyList(node)) {
var arg = evaluate(node.car, { env, dynamic_scope, error });
if (false && dynamic_scope) {
if (dynamic_scope) {
arg = unpromise(arg, arg => {
if (typeof arg === 'function') {
if (typeof arg === 'function' && isNativeFunction(arg)) {
return arg.bind(dynamic_scope);
}
return arg;
Expand Down

0 comments on commit 41862f5

Please sign in to comment.