[gjs] promise: Get node-isms to work
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] promise: Get node-isms to work
- Date: Tue, 13 Dec 2016 19:34:45 +0000 (UTC)
commit 4c326a5aa3f5df18c933e9e989009fd15ab01440
Author: Philip Chimento <philip chimento gmail com>
Date: Sat Jan 23 12:20:28 2016 -0800
promise: Get node-isms to work
This adds some stubs to lie.js for node.js-related objects that it
expects to be present, such as "process".
It implements "require" as well, and provides an implementation of
immediate.js using GLib. It would have been somewhat feasible to port
immediate.js, but it requires either a DOM or setTimeout(), so we would
have had to basically write this implementation anyway.
It also wraps the whole thing in an IIFE so that symbols are not leaked
out of the scope, and returns the Promise object so that it will be the
result of calling JS::Evaluate() on the code.
https://bugzilla.gnome.org/show_bug.cgi?id=608450
modules/_lie.js | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/modules/_lie.js b/modules/_lie.js
index 69a9529..9cf528a 100644
--- a/modules/_lie.js
+++ b/modules/_lie.js
@@ -1,3 +1,29 @@
+// jscs:disable validateIndentation
+(function () {
+const GLib = imports.gi.GLib;
+
+var reqs = {
+ immediate: function () {
+ return function (func, priority=GLib.PRIORITY_DEFAULT_IDLE) {
+ GLib.idle_add(priority, function () {
+ func();
+ return GLib.SOURCE_REMOVE;
+ });
+ };
+ },
+};
+function require(req) {
+ return reqs[req]();
+}
+
+var process = {
+ emit: function (event, error) {
+ if (event === 'unhandledRejection')
+ log('Unhandled rejection');
+ throw error;
+ },
+};
+
// Copyright (c) 2014 Calvin Metcalf
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -38,7 +64,7 @@ if (!process.browser) {
var UNHANDLED = ['UNHANDLED'];
}
-module.exports = Promise;
+// module.exports = Promise; // removed for GJS
function Promise(resolver) {
if (typeof resolver !== 'function') {
@@ -301,3 +327,6 @@ function race(iterable) {
}
// END CODE FROM lie/lib/index.js
+
+return Promise;
+})();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]