[gjs/wip/ptomato/classes: 9/12] class: Move to ES6 classes in internal code
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/wip/ptomato/classes: 9/12] class: Move to ES6 classes in internal code
- Date: Thu, 3 Aug 2017 01:47:09 +0000 (UTC)
commit a25952de0a13c4c86b17356bea8d3f07ff359b4f
Author: Philip Chimento <philip chimento gmail com>
Date: Sun Jul 23 21:10:38 2017 -0700
class: Move to ES6 classes in internal code
Where possible, move usage of Lang.Class within GJS to use ES6 classes.
That is currently possible for any classes which don't inherit from
GObject classes and don't implement Lang.Interfaces.
Remove the documentation for the Lang.Class class framework, as it's now
become outdated.
https://bugzilla.gnome.org/show_bug.cgi?id=785652
doc/Class_Framework.md | 98 -------------------------------------
installed-tests/js/minijasmine.js | 30 +++++------
installed-tests/js/testLang.js | 12 ++---
installed-tests/js/testSignals.js | 7 +--
4 files changed, 21 insertions(+), 126 deletions(-)
---
diff --git a/installed-tests/js/minijasmine.js b/installed-tests/js/minijasmine.js
index b03c205..6af74e3 100644
--- a/installed-tests/js/minijasmine.js
+++ b/installed-tests/js/minijasmine.js
@@ -48,19 +48,17 @@ Lang.copyProperties(jasmineInterface, window);
// Reporter that outputs according to the Test Anything Protocol
// See http://testanything.org/tap-specification.html
-const TapReporter = new Lang.Class({
- Name: 'TapReporter',
-
- _init: function () {
+class TapReporter {
+ constructor() {
this._failedSuites = [];
this._specCount = 0;
- },
+ }
- jasmineStarted: function (info) {
+ jasmineStarted(info) {
print('1..' + info.totalSpecsDefined);
- },
+ }
- jasmineDone: function () {
+ jasmineDone() {
this._failedSuites.forEach(failure => {
failure.failedExpectations.forEach(result => {
print('not ok - An error was thrown outside a test');
@@ -69,9 +67,9 @@ const TapReporter = new Lang.Class({
});
window._jasmineMain.quit();
- },
+ }
- suiteDone: function (result) {
+ suiteDone(result) {
if (result.failedExpectations && result.failedExpectations.length > 0) {
window._jasmineRetval = 1;
this._failedSuites.push(result);
@@ -80,13 +78,13 @@ const TapReporter = new Lang.Class({
if (result.status === 'disabled') {
print('# Suite was disabled:', result.fullName);
}
- },
+ }
- specStarted: function () {
+ specStarted() {
this._specCount++;
- },
+ }
- specDone: function (result) {
+ specDone(result) {
let tap_report;
if (result.status === 'failed') {
window._jasmineRetval = 1;
@@ -110,7 +108,7 @@ const TapReporter = new Lang.Class({
print(stackTrace.split('\n').map((str) => '# ' + str).join('\n'));
});
}
- },
-});
+ }
+}
window._jasmineEnv.addReporter(new TapReporter());
diff --git a/installed-tests/js/testLang.js b/installed-tests/js/testLang.js
index 1e0d307..13735e6 100644
--- a/installed-tests/js/testLang.js
+++ b/installed-tests/js/testLang.js
@@ -53,16 +53,14 @@ describe('Lang module', function () {
describe('bind()', function () {
- const Obj = new Lang.Class({
- Name: 'Obj',
- callback: function () {
- return true;
- },
- });
let o;
beforeEach(function () {
- o = new Obj();
+ o = {
+ callback() {
+ return true;
+ }
+ };
spyOn(o, 'callback').and.callThrough();
});
diff --git a/installed-tests/js/testSignals.js b/installed-tests/js/testSignals.js
index 5944b29..58d3530 100644
--- a/installed-tests/js/testSignals.js
+++ b/installed-tests/js/testSignals.js
@@ -8,14 +8,11 @@ const Foo = new Lang.Class({
_init: function () {},
});
-describe('Object with signals', function () {
+describe('Legacy object with signals', function () {
testSignals(Foo);
});
-const FooWithoutSignals = new Lang.Class({
- Name: 'FooWithoutSignals',
- _init: function () {},
-});
+class FooWithoutSignals {}
Signals.addSignalMethods(FooWithoutSignals.prototype);
describe('Object with signals added', function () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]