diff --git a/lib/node_modules/@stdlib/proxy/ctor/lib/polyfill.js b/lib/node_modules/@stdlib/proxy/ctor/lib/polyfill.js index 9fb7ee4ff475..5061df0bf666 100644 --- a/lib/node_modules/@stdlib/proxy/ctor/lib/polyfill.js +++ b/lib/node_modules/@stdlib/proxy/ctor/lib/polyfill.js @@ -44,11 +44,39 @@ * var x = p.a; * // returns 6.28 */ -function Proxy( target ) { - // TODO: polyfill implementation - return target; +function Proxy( target, handlers ) { + // Check if handlers and the 'get' trap function are provided + if (typeof handlers !== 'object' || typeof handlers.get !== 'function') { + throw new TypeError('Expected handlers to be an object with a "get" function.'); + } + + // Return a proxied object that intercepts property access + return new ProxyImpl(target, handlers); } +/** +* Polyfill for the Proxy internals. +* This is the object that will mimic the behavior of the Proxy API. +*/ +function ProxyImpl(target, handlers) { + this.target = target; + this.handlers = handlers; + + return new Proxy(this, { + get: function(obj, prop) { + // Call the 'get' handler if defined + if (prop in handlers) { + return handlers[prop](target, prop); + } + // Otherwise, return the property from the target object + return target[prop]; + }, + set: function(obj, prop, value) { + target[prop] = value; + return true; + } + }); +} // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/prev-grapheme-cluster-break/lib/main.js b/lib/node_modules/@stdlib/string/prev-grapheme-cluster-break/lib/main.js index 5395038e6e4c..467c9b35a3c9 100644 --- a/lib/node_modules/@stdlib/string/prev-grapheme-cluster-break/lib/main.js +++ b/lib/node_modules/@stdlib/string/prev-grapheme-cluster-break/lib/main.js @@ -62,69 +62,70 @@ var emojiProperty = grapheme.emojiProperty; * var out = prevGraphemeClusterBreak( '🌷', 1 ); * // returns -1 */ +// cspell:ignore अनुच्छेद function prevGraphemeClusterBreak( str, fromIndex ) { - var breaks; - var emoji; - var ans; - var len; - var idx; - var cp; - var i; - - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - len = str.length; - if ( arguments.length > 1 ) { - if ( !isInteger( fromIndex ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); - } - idx = fromIndex; - } else { - idx = len - 1; - } - if ( len === 0 || idx <= 0 ) { - return -1; - } - if ( idx >= len ) { - idx = len - 1; - } - - // Initialize caches for storing grapheme break and emoji properties: - breaks = []; - emoji = []; - - // Get the code point for the starting index: - cp = codePointAt( str, 0 ); - - // Get the corresponding grapheme break and emoji properties: - breaks.push( breakProperty( cp ) ); - emoji.push( emojiProperty( cp ) ); - - ans = -1; - for ( i = 1; i <= idx; i++ ) { - // If the current character is part of a surrogate pair, move along... - if ( hasUTF16SurrogatePairAt( str, i-1 ) ) { - ans = i-2; - breaks.length = 0; - emoji.length = 0; - continue; - } - cp = codePointAt( str, i ); - - // Get the corresponding grapheme break and emoji properties: - breaks.push( breakProperty( cp ) ); - emoji.push( emojiProperty( cp ) ); - - // Determine if we've encountered a grapheme cluster break... - if ( breakType( breaks, emoji ) > 0 ) { - ans = i-1; - breaks.length = 0; - emoji.length = 0; - continue; - } - } - return ans; + var breaks; + var emoji; + var ans; + var len; + var idx; + var cp; + var i; + + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + } + len = str.length; + if ( arguments.length > 1 ) { + if ( !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + idx = fromIndex; + } else { + idx = len - 1; + } + if ( len === 0 || idx <= 0 ) { + return -1; + } + if ( idx >= len ) { + idx = len - 1; + } + + // Initialize caches for storing grapheme break and emoji properties: + breaks = []; + emoji = []; + + // Get the code point for the starting index: + cp = codePointAt( str, 0 ); + + // Get the corresponding grapheme break and emoji properties: + breaks.push( breakProperty( cp ) ); + emoji.push( emojiProperty( cp ) ); + + ans = -1; + for ( i = 1; i <= idx; i++ ) { + // If the current character is part of a surrogate pair, move along... + if ( hasUTF16SurrogatePairAt( str, i-1 ) ) { + ans = i-2; + breaks.length = 0; + emoji.length = 0; + continue; + } + cp = codePointAt( str, i ); + + // Get the corresponding grapheme break and emoji properties: + breaks.push( breakProperty( cp ) ); + emoji.push( emojiProperty( cp ) ); + + // Determine if we've encountered a grapheme cluster break... + if ( breakType( breaks, emoji ) > 0 ) { + ans = i-1; + breaks.length = 0; + emoji.length = 0; + continue; + } + } + return ans; } diff --git a/test/proxy-polyfill.test.js b/test/proxy-polyfill.test.js new file mode 100644 index 000000000000..0e381df2f2fb --- /dev/null +++ b/test/proxy-polyfill.test.js @@ -0,0 +1,15 @@ +const Proxy = require('../lib/proxy/ctor/polyfill'); // Assuming the polyfill is inside the 'lib' folder + +// Define a simple handler +const handler = { + get: (target, prop) => prop in target ? target[prop] * 2 : 0 +}; + +// Create a proxied object +const obj = new Proxy({}, handler); + +// Add a property +obj.a = 5; + +// Check if the polyfill works +console.log(obj.a); // Should output 10, since it's doubled by the 'get' handler