JavaScript has a TypedArray class, it's just hidden.
To access it, one simply needs to do:
const TypedArray = Object.getPrototypeOf(Uint8Array.prototype).constructor
You can then use it with the instanceof operator.
JavaScript has a TypedArray class, it's just hidden.
To access it, one simply needs to do:
const TypedArray = Object.getPrototypeOf(Uint8Array.prototype).constructor
You can then use it with the instanceof operator.
See also:
const AsyncFunction = (async _=>_).constructor;What other standard JavaScript classes are hidden like this without a global reference?
Some of these are actual working constructors, e.g. you can do:
let g_ = new GeneratorFunction('let i = 0; while (1) yield i++;')();This is, of course, "sparkling eval". Content-Security-Policy probably treats it as such, otherwise I just accidentally dropped 0-day.
My partner's mother bought me a club mate for Christmas, and between the caffeine rush and how much the commercials playing during the football(🏈) game that's on the TV are making me despise capitalism, I'm shitposting to cope.
@cyclophora LOL.
Seriously though, it's just like the regular Function constructor, except for generator functions.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function
Literally eval with extra steps.
@ryanc wait why does it take a string
@f4grx Some might consider this knowledge unnatural but knowing it pays well enough to be worth the psychic damage.
@ryanc programming language of the utterly deranged, look at what they are asking your respect for all this time.
@ryanc what is the point of this why does it not take another function or something. I'm crying blood please help
@ryanc was it added before people realized eval was a bad idea?
@cyclophora The Function() constructor? That's been around for ages. Folks knew better by the time generator functions were a thing, but violence was chosen.
There are so many ways to do eval in JavaScript, though.
@ryanc i feel like there should be a way to turn off eval from inside JS in addition to CSP
@cyclophora Did you know that settimeout can take a string argument?
You can add an invisible button to the dom with an onclick attribute that's a string of code and then call .click() on it.
Create an iframe with a javascript:... URI.
It's a bit of a lost cause.
Also, I've written bytecode interpreters in JavaScript that can run arbitrary code and bypass CSP restrictions.
@ge0rg Mostly sarcasm. There are more sensible ways to detect whether something is a typed array.
@ryanc
Not sure if sarcasm or actual Javascript usability improvement... or both?!
GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.
All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.