Welcome! Log In Create A New Profile

Advanced

[njs] Making built-in prototypes mutable.

Dmitry Volyntsev
November 22, 2018 11:14AM
details: https://hg.nginx.org/njs/rev/82cbeec8fd19
branches:
changeset: 667:82cbeec8fd19
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Nov 22 18:55:32 2018 +0300
description:
Making built-in prototypes mutable.

diffstat:

njs/njs_builtin.c | 2 ++
njs/test/njs_unit_test.c | 20 ++++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)

diffs (67 lines):

diff -r 6577d408d494 -r 82cbeec8fd19 njs/njs_builtin.c
--- a/njs/njs_builtin.c Thu Nov 22 18:12:26 2018 +0300
+++ b/njs/njs_builtin.c Thu Nov 22 18:55:32 2018 +0300
@@ -358,6 +358,8 @@ njs_builtin_objects_create(njs_vm_t *vm)
return NXT_ERROR;
}

+ prototype->object.extensible = 1;
+
prototype++;
}

diff -r 6577d408d494 -r 82cbeec8fd19 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Nov 22 18:12:26 2018 +0300
+++ b/njs/test/njs_unit_test.c Thu Nov 22 18:55:32 2018 +0300
@@ -338,6 +338,10 @@ static njs_unit_test_t njs_test[] =
{ nxt_string(".e1"),
nxt_string("SyntaxError: Unexpected token \".\" in 1") },

+ { nxt_string("Number.prototype.X = function(){return 123;};"
+ "(1).X()"),
+ nxt_string("123") },
+
/* Indexes. */

{ nxt_string("var a = []; a[-1] = 2; a[-1] == a['-1']"),
@@ -2731,10 +2735,16 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var o = Object.create({a:1}); o.a = 2; delete o.a; o.a"),
nxt_string("1") },

+ /* Inheritance. */
+
{ nxt_string("function Foo() {this.bar = 10;}; Foo.prototype.bar = 42; "
"var v = new Foo(); delete v.bar; v.bar"),
nxt_string("42") },

+ { nxt_string("function Cl(x,y) {this.x = x; this.y = y}; "
+ "var c = new Cl('a', 'b'); Cl.prototype.z = 1; c.z"),
+ nxt_string("1") },
+
/* Math object is immutable. */

{ nxt_string("delete Math.max"),
@@ -3771,6 +3781,12 @@ static njs_unit_test_t njs_test[] =
" a = b"),
nxt_string("abcdefghijklmnop") },

+ { nxt_string("String.prototype.my = function f() {return 7}; 'a'.my()"),
+ nxt_string("7") },
+
+ { nxt_string("'a'.my"),
+ nxt_string("undefined") },
+
/* Escape strings. */

{ nxt_string("'\\a \\' \\\" \\\\ \\0 \\b \\f \\n \\r \\t \\v'"),
@@ -5271,6 +5287,10 @@ static njs_unit_test_t njs_test[] =
"(function(){(function(){(function(){})})})})})})})"),
nxt_string("SyntaxError: The maximum function nesting level is \"5\" in 1") },

+ { nxt_string("Function.prototype.toString = function () {return 'X'};"
+ "eval"),
+ nxt_string("X") },
+
/* Recursive factorial. */

{ nxt_string("function f(a) {"
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Making built-in prototypes mutable.

Dmitry Volyntsev 286 November 22, 2018 11:14AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 217
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready