From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from resqmta-ch2-10v.sys.comcast.net (resqmta-ch2-10v.sys.comcast.net [IPv6:2001:558:fe21:29:69:252:207:42]) by hurricane.the-brannons.com (Postfix) with ESMTPS id 9928177CCA for ; Sat, 13 Jun 2015 03:49:31 -0700 (PDT) Received: from resomta-ch2-05v.sys.comcast.net ([69.252.207.101]) by resqmta-ch2-10v.sys.comcast.net with comcast id fmqj1q0032Bo0NV01mqqMe; Sat, 13 Jun 2015 10:50:50 +0000 Received: from eklhad ([IPv6:2601:4:5380:4ee:21e:4fff:fec2:a0f1]) by resomta-ch2-05v.sys.comcast.net with comcast id fmqq1q0025LMg2101mqquD; Sat, 13 Jun 2015 10:50:50 +0000 To: Edbrowse-dev@lists.the-brannons.com From: Karl Dahlke Reply-to: Karl Dahlke References: <20150513044849.eklhad@comcast.net> User-Agent: edbrowse/3.5.4.1+ Date: Sat, 13 Jun 2015 06:50:49 -0400 Message-ID: <20150513065049.eklhad@comcast.net> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1434192650; bh=pedqNzgfq7eqdKSohT9xVMewaq2X7WvrPri57LG4s20=; h=Received:Received:To:From:Reply-to:Subject:Date:Message-ID: Mime-Version:Content-Type; b=XIf9d9hkVTL9EPKGEfm8LuerFLzrZSidjgsKTzz+lEyAjcrXfKfTI2Q4D6QThydlr 3HxManjtMNU7PgEquD0ilgGaK6E4cEsrEyy2LIMyLTlPavCt9PqWS7QOh/w59vKNZz DKyWquaSVJ0B96UNNyt9w+uVXxxHPuD2Hw8AtsM4y1QOZXiBYLcvPcE58p3ZbC1rxa 57iduvioR/8fAi+62etqs3K5I3BEr982KLUQjp8nEgI37J/Zs0fLegstg5T47ZSN27 ulyvPFukY7rwIk0QfvAoUn3D8q6JfuBvzuKWSJobW1OITRwiaSMN219EBU1gQwTIkb 8yK4hfi4rlNtw== Subject: [Edbrowse-dev] getters and setters in straight javascript X-BeenThere: edbrowse-dev@lists.the-brannons.com X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Edbrowse Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Jun 2015 10:49:32 -0000 This is a followup to my previous message. If getters and setters are feasible in straight javascript, here is how the url class would look. If you paste this into startwindow.js it compiles properly. The syntax is right. And the code looks right to me, but of course it blows up because there are then js setters and C setters and they collide. I would have to remove the C setters from jseng-moz.cpp. Anyways here it is to give us an idea of how js setters, for the URL class, would look, using much less code, independent of the js engine. Now I need to step back and just think about it for a bit. don't worry, I haven't pushed anything, I'm just playing. var $urlpro = URL.prototype; /* rebuild the href string from its components. * Call this when a component changes. * All components are strings, except for port, * and all should be defined, even if they are empty. */ $urlpro.rebuild = function() { var h = ""; if(this.protocol$val.length) { h = this.protocol$val + "://"; } if(this.host$val.length) { h += this.host$val; } else if(this.hostname$val.length) { h += this.hostname$val; if(this.port$val != 0) h += ":" + this.port$val; } if(this.pathname$val.length) { // pathname should always begin with /, should we check for that? h += this.pathname$val; } if(this.search$val.length) { // search should always begin with ?, should we check for that? h += this.search$val; } if(this.hash$val.length) { // hash should always begin with #, should we check for that? h += this.hash$val; } this.href$val = h; }; Object.defineProperty($urlpro, "protocol", { get: function() {return this.protocol$val; }, set: function(v) { this.protocol$val = v; this.rebuild(); } }); Object.defineProperty($urlpro, "pathname", { get: function() {return this.pathname$val; }, set: function(v) { this.pathname$val = v; this.rebuild(); } }); Object.defineProperty($urlpro, "search", { get: function() {return this.search$val; }, set: function(v) { this.search$val = v; this.rebuild(); } }); Object.defineProperty($urlpro, "hash", { get: function() {return this.hash$val; }, set: function(v) { this.hash$val = v; this.rebuild(); } }); Object.defineProperty($urlpro, "port", { get: function() {return this.port$val; }, set: function(v) { this.port$val = v; if(this.hostname$val.length) this.host$val = this.hostname$val + ":" + v; this.rebuild(); } }); Object.defineProperty($urlpro, "hostname", { get: function() {return this.hostname$val; }, set: function(v) { this.hostname$val = v; if(this.port$val) this.host$val = v + ":" + this.port$val; this.rebuild(); } }); Object.defineProperty($urlpro, "href", { get: function() {return this.href$val; }, set: function(v) { this.href$val = v; // initialize components to empty, // then fill them in from href if they are present */ this.protocol$val = ""; this.hostname$val = ""; this.port$val = 0; this.host$val = ""; this.pathname$val = ""; this.search$val = ""; this.hash$val = ""; if(v.match(/^[a-zA-Z]+:\/\//)) { this.protocol$val = v.replace(/:\/\/.*/, ""); v = v.replace(/^[a-zA-z]+:\/\//, ""); } if(v.match(/[/#?]/)) { /* contains / ? or # */ this.host$val = v.replace(/[/#?].*/, ""); v = v.replace(/^[^/#?]*/, ""); } else { /* no / ? or #, the whole thing is the host, www.foo.bar */ this.host$val = v; v = ""; } if(this.host$val.match(/:/)) { this.hostname$val = this.host$val.replace(/:.*/, ""); this.port$val = this.host$val.replace(/^.*:/, ""); /* port has to be an integer */ this.port$val = parseInt(this.port$val); } else { this.hostname$val = this.host$val; } if(v.match(/[#?]/)) { this.pathname$val = v.replace(/[#?].*/, ""); v = v.replace(/^[^#?]*/, ""); } else { this.pathmname$val = v; v = ""; } if(this.pathname$val == "") this.pathname$val = "/"; if(v.match(/#/)) { this.search$val = v.replace(/#.*/, ""); this.hash$val = v.replace(/^[^#]*/, ""); } else { this.search$val = v; } } });